Class: DummyOscar::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/dummy_oscar/cli.rb

Constant Summary collapse

CMD =
'dummy_oscar'
USAGE =
<<~USAGE
sub commands are:
   s :     run with server mode
   c :     run with client mode
See '#{CMD} COMMAND --help' for more information on a specific command.
USAGE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



27
28
29
30
# File 'lib/dummy_oscar/cli.rb', line 27

def initialize(argv)
  @argv = argv
  @options = {}
end

Class Method Details

.start(argv = ARGV) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/dummy_oscar/cli.rb', line 7

def start(argv = ARGV)
  cli = new(argv)
  options = cli.parse

  if options[:mode] == "s"
    DummyOscar::Server.new(config_file: options[:config], port: options[:port], library: options[:library]).start
  else
    DummyOscar::Client.new(config_file: options[:config], command: options[:command], library: options[:library], host: options[:host]).start
  end
end

Instance Method Details

#parseObject

Raises:

  • (OptionParser::MissingArgument)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dummy_oscar/cli.rb', line 32

def parse
  global_command.order!(@argv)
  @options[:mode] = @argv.shift
  subcommand = subcommands[@options[:mode]]
  unless subcommand
    puts global_command.help
    exit!
  end

  subcommand.order!(@argv)
  raise OptionParser::MissingArgument.new("-C") if @options[:config].nil?
  @options
end