Class: Shoes::UI::CLI

Inherits:
Object
  • Object
show all
Defined in:
shoes-core/lib/shoes/ui/cli.rb,
shoes-core/lib/shoes/ui/cli/base_command.rb,
shoes-core/lib/shoes/ui/cli/help_command.rb,
shoes-core/lib/shoes/ui/cli/manual_command.rb,
shoes-core/lib/shoes/ui/cli/default_command.rb,
shoes-core/lib/shoes/ui/cli/package_command.rb,
shoes-core/lib/shoes/ui/cli/samples_command.rb,
shoes-core/lib/shoes/ui/cli/version_command.rb,
shoes-core/lib/shoes/ui/cli/select_backend_command.rb

Defined Under Namespace

Classes: BaseCommand, DefaultCommand, HelpCommand, ManualCommand, PackageCommand, SamplesCommand, SelectBackendCommand, VersionCommand

Constant Summary collapse

SUPPORTED_COMMANDS =
{
  help:           HelpCommand,
  manual:         ManualCommand,
  package:        PackageCommand,
  samples:        SamplesCommand,
  select_backend: SelectBackendCommand,
  version:        VersionCommand,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(backend) ⇒ CLI

Returns a new instance of CLI.



27
28
29
30
31
# File 'shoes-core/lib/shoes/ui/cli.rb', line 27

def initialize(backend)
  $LOAD_PATH.unshift(Dir.pwd)
  backend_const = Shoes.load_backend(backend)
  backend_const.initialize_backend
end

Instance Method Details

#create_command(*args) ⇒ Object



43
44
45
46
# File 'shoes-core/lib/shoes/ui/cli.rb', line 43

def create_command(*args)
  command_class = SUPPORTED_COMMANDS[args.first.to_sym] || DefaultCommand
  command_class.new(*args.dup)
end

#run(args) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'shoes-core/lib/shoes/ui/cli.rb', line 33

def run(args)
  if args.empty?
    Shoes::UI::CLI::HelpCommand.new.run
    exit(1)
  end

  command = create_command(*args)
  command.run
end