Class: Scatter::CLI
- Inherits:
-
Object
- Object
- Scatter::CLI
- Defined in:
- lib/scatter/cli.rb
Instance Method Summary collapse
-
#initialize(out) ⇒ CLI
constructor
A new instance of CLI.
- #run(args) ⇒ Object
- #run!(args) ⇒ Object
Constructor Details
#initialize(out) ⇒ CLI
Returns a new instance of CLI.
3 4 5 |
# File 'lib/scatter/cli.rb', line 3 def initialize(out) @out = out end |
Instance Method Details
#run(args) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/scatter/cli.rb', line 30 def run(args) run!(args) rescue CommandLineError => e @out.puts "Error: #{e.}" usage end |
#run!(args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/scatter/cli.rb', line 7 def run!(args) raise CommandLineError, 'No command given' if args.empty? case command_name = args.shift when /^-?-?h(elp)?$/ if args.empty? usage else if args.first == 'commands' commands_help else @out.puts command_class(args.first).help end end when /^-?-?v(ersion)?$/ @out.puts "scatter version #{Scatter.version}" else klass = command_class(command_name) command = klass.new(@out, *args) command.execute! end end |