Class: Testjour::CLI::Parser
- Inherits:
-
Object
- Object
- Testjour::CLI::Parser
- Defined in:
- lib/testjour/cli.rb
Class Attribute Summary collapse
-
.commands ⇒ Object
Returns the value of attribute commands.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.commands ⇒ Object
Returns the value of attribute commands.
26 27 28 |
# File 'lib/testjour/cli.rb', line 26 def commands @commands end |
Class Method Details
.register_command(klass) ⇒ Object
28 29 30 |
# File 'lib/testjour/cli.rb', line 28 def register_command(klass) @commands << klass end |
Instance Method Details
#command_klass ⇒ Object
51 52 53 54 55 |
# File 'lib/testjour/cli.rb', line 51 def command_klass self.class.commands.detect do |command_klass| command_klass.command == command_name end end |
#command_name ⇒ Object
57 58 59 |
# File 'lib/testjour/cli.rb', line 57 def command_name ARGV.first end |
#execute ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/testjour/cli.rb', line 35 def execute begin raise NoCommandGiven if ARGV.empty? raise UnknownCommand.new(command_name) unless command_klass args = ARGV.dup args.shift # Remove subcommand name command_klass.new(self, args).run rescue NoCommandGiven, UnknownCommand $stderr.puts "ERROR: #{$!.message}" $stderr.puts usage exit 1 end end |
#usage ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/testjour/cli.rb', line 61 def usage = [] << "usage: testjour <SUBCOMMAND> [OPTIONS] [ARGS...]" << "Type 'testjour help <SUBCOMMAND>' for help on a specific subcommand." << "Type 'testjour version' to get this program's version." << "" << "Available subcommands are:" self.class.commands.sort_by { |c| c.command }.each do |command_klass| << " " + command_klass.command end .map { |line| line.chomp }.join("\n") end |