Class: Heroics::CLI
- Inherits:
-
Object
- Object
- Heroics::CLI
- Defined in:
- lib/heroics/cli.rb
Instance Method Summary collapse
-
#initialize(name, commands, output) ⇒ CLI
constructor
Instantiate a CLI for an API described by a JSON schema.
-
#run(*parameters) ⇒ Object
Run a command.
Constructor Details
#initialize(name, commands, output) ⇒ CLI
Instantiate a CLI for an API described by a JSON schema.
10 11 12 13 14 |
# File 'lib/heroics/cli.rb', line 10 def initialize(name, commands, output) @name = name @commands = commands @output = output end |
Instance Method Details
#run(*parameters) ⇒ Object
Run a command.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/heroics/cli.rb', line 21 def run(*parameters) name = parameters.shift if name.nil? || name == 'help' if command_name = parameters.first command = @commands[command_name] command.usage else usage end else command = @commands[name] if command.nil? @output.write("There is no command called '#{name}'.\n") else command.run(*parameters) end end end |