Class: Boot::Lib::Core::SubCommand
- Inherits:
-
Object
- Object
- Boot::Lib::Core::SubCommand
- Defined in:
- lib/Boot/Lib/Core/SubCommand.rb
Instance Attribute Summary collapse
-
#assume_help ⇒ Object
readonly
If true, print help message on empty args.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, description, options, assume_help = true, &block) ⇒ SubCommand
constructor
A new instance of SubCommand.
- #print_help_message ⇒ Object
- #run(args) ⇒ Object
Constructor Details
#initialize(name, description, options, assume_help = true, &block) ⇒ SubCommand
Returns a new instance of SubCommand.
10 11 12 13 14 15 16 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 10 def initialize(name, description, , assume_help = true, &block) @name = name @description = description @options = @block = block @assume_help = assume_help end |
Instance Attribute Details
#assume_help ⇒ Object (readonly)
If true, print help message on empty args
8 9 10 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 8 def assume_help @assume_help end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 4 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 3 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 5 def @options end |
Class Method Details
.is_flag(str) ⇒ Object
39 40 41 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 39 def self.is_flag(str) return str.start_with?("--") || (str.start_with?("-") && str.length == 2) end |
Instance Method Details
#print_help_message ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 43 def puts 'boot ' + @name if (@description != '') puts "\tDescription:" puts "\t" + @description end if @options..length > 0 puts puts "\tArguments:" @options.each do |a| print "\t" + '%-16.16s' % (a.flags * ', ') print "\t" print a.desc + "\n" end end puts end |
#run(args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/Boot/Lib/Core/SubCommand.rb', line 18 def run(args) begin # If no option spesified, assume --help # The underscore is a hack, see rescue block if (assume_help) fail Slop::UnknownOption.new "Unknown option --help", "--help" if (args.length == 0) end @options.parse(args); # Dryrun to check for argument errors @block.call(@options, args) rescue Slop::UnknownOption => e # Hack to get around the lack of e.getUnknownOption() # TODO Fix once avaiable if (e.flag == '--help') else puts "#{e.}. Try boot #{@name} --help" end end end |