Genshin/GAKUEngine

View on GitHub
bin/gaku

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
require 'thor'
require_relative '../lib/gaku/container'
require_relative '../lib/gaku/command/installer'

class GakuCLI < Thor
  desc 'version', 'Prints the version of the installed gaku gem (from which this command is being run).'
  def version()
    require 'rubygems'
    spec = Gem::Specification::load("#{__dir__}/../gaku.gemspec")
    puts spec.version
  end

  desc 'new [APP_PATH]', 'Creates a new installation of GAKU Engine at APP_PATH.'
  long_desc "Creates a new application in the current directory or in the specificed path."
  def new(path = './')
    real_path = File.expand_path(path)
    puts "Creating new GAKU Engine installation at #{path}"
  end

  desc 'update', 'Updates an installation of GAKU Engine.'
  def update()
    puts 'WIP'
  end

  desc 'install', 'Installs GAKU into the OS as a service.'
  def install()
    puts 'WIP'
  end
  
  desc 'backup [BACKUP_PATH]', 'Creates a full backup of the current GAKU installation in BACKUP_PATH.'
  def backup(path = './backup/')
    real_path = File.expand_path(path)
    time = DateTime.now()
    puts "Creating a GAKU Engine backup at #{path}/GAKU-backup-#{time}.tar.xz"
    puts 'WIP'
  end

  desc 'restore [BACKUP_PATH]', 'Restores a full backup of a GAKU installation from BACKUP_PATH.'
  def restore(path = '')
    if path == ''
      puts 'Backup not specified. Aborting restore.'
      return
    end
    restore_path = File.expand_path(path)
    puts "Restoring GAKU Engine backup from #{path}"
    puts 'WIP'
  end

  class Container < Thor
    desc 'start', 'Starts a container, using local Docker settings if found in current directory.'
    def start
      ::Gaku::Container.Start
    end

    desc 'stop', 'Stops running containers.'
    def stop
      ::Gaku::Container.Stop
    end

    desc 'delete', 'Deletes container data, stopping running containers if needed.'
    def delete
      ::Gaku::Container.Delete
    end

    desc 'console', 'Connects to a console session on a running container.'
    def console
      ::Gaku::Container.Console
    end

    desc 'sample', 'Seeds sample data to running container.'
    def sample
      ::Gaku::Container.Sample
    end

    desc 'terminal', 'Opens up a terminal connection to the running container'
    def terminal
      ::Gaku::Container.Terminal
    end

    desc 'testing', 'Sets up the container as a testing target to run specs'
    def testing
      ::Gaku::Container.Testing
    end

    desc 'detach', 'Detaches from the container session'
    def detach
      ::Gaku::Container.Detach
    end
  end

  desc 'container', 'Build and run GAKU containers using Docker.'
  subcommand 'container', GakuCLI::Container
end

GakuCLI.start(ARGV)