Class: DummyOscar::Cli
- Inherits:
-
Object
- Object
- DummyOscar::Cli
- 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
-
#initialize(argv) ⇒ Cli
constructor
A new instance of Cli.
- #parse ⇒ Object
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) = cli.parse if [:mode] == "s" DummyOscar::Server.new(config_file: [:config], port: [:port], library: [:library]).start else DummyOscar::Client.new(config_file: [:config], command: [:command], library: [:library], host: [:host]).start end end |
Instance Method Details
#parse ⇒ Object
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 |