Class: CommandLineUtils::Commands
- Inherits:
-
Object
- Object
- CommandLineUtils::Commands
- Defined in:
- lib/command-line-utils/commands.rb
Instance Attribute Summary collapse
-
#command_options ⇒ Object
Returns the value of attribute command_options.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize ⇒ Commands
constructor
A new instance of Commands.
Constructor Details
#initialize ⇒ Commands
Returns a new instance of Commands.
9 10 11 12 13 14 |
# File 'lib/command-line-utils/commands.rb', line 9 def initialize @commands = ["help"] @help = false @summery = "" @banner = "" end |
Instance Attribute Details
#command_options ⇒ Object
Returns the value of attribute command_options.
8 9 10 |
# File 'lib/command-line-utils/commands.rb', line 8 def @command_options end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
7 8 9 |
# File 'lib/command-line-utils/commands.rb', line 7 def commands @commands end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/command-line-utils/commands.rb', line 8 def @options end |
Instance Method Details
#help ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/command-line-utils/commands.rb', line 16 def help opt = OptionParser.new opt.parse!(@command_options) @summery = "Show command helps." @banner = "command" return opt if @help @help = true command = @command_options.shift raise UsageException unless command raise "Unknown command: " + command unless commands.include?(command) opt = send(command.gsub(/:/,"_")) puts "Summery: #{@summery}" opt. += " #{command} #{@banner}" if opt puts opt if opt end |