Class: Vnehm::Command
- Inherits:
-
Object
- Object
- Vnehm::Command
- Defined in:
- lib/vnehm/command.rb
Overview
Base class for all Vnehm commands. When creating a new vnehm command, define #initialize, #execute, #arguments, #program_name, #summary and #usage (as appropriate) See the above mentioned methods for details
Direct Known Subclasses
ConfigureCommand, DlCommand, GetCommand, HelpCommand, TracksViewCommand, VersionCommand
Instance Attribute Summary collapse
-
#options ⇒ Object
Hash with options of the command.
-
#options_descs ⇒ Object
Hash with descriptions of each option.
Instance Method Summary collapse
-
#add_option(option, usage, desc) ⇒ Object
Add a command-line option.
-
#arguments ⇒ Object
Override to provide details of the arguments a command takes.
-
#execute ⇒ Object
Override to provide command handling.
-
#handle_options(args) ⇒ Object
Handle the given list of arguments by parsing them and recording the results.
-
#initialize ⇒ Command
constructor
In ‘initialize’ should be defined all options by method ‘add_option’ See get_command.rb as example.
-
#invoke(args) ⇒ Object
Invoke the command with the given list of arguments.
-
#program_name ⇒ Object
The name of the command for command-line invocation.
-
#summary ⇒ Object
Override to display a short description of what this command does.
-
#usage ⇒ Object
Override to display the usage for an individual vnehm command.
Constructor Details
#initialize ⇒ Command
In ‘initialize’ should be defined all options by method ‘add_option’ See get_command.rb as example
27 28 29 30 |
# File 'lib/vnehm/command.rb', line 27 def initialize @options = {} @options_descs = {} end |
Instance Attribute Details
#options ⇒ Object
Hash with options of the command
16 17 18 |
# File 'lib/vnehm/command.rb', line 16 def @options end |
#options_descs ⇒ Object
Hash with descriptions of each option
21 22 23 |
# File 'lib/vnehm/command.rb', line 21 def @options_descs end |
Instance Method Details
#add_option(option, usage, desc) ⇒ Object
Add a command-line option
Vnehm don’t use options with dashes to be more user-friendly
See ‘get_command.rb’ as example
102 103 104 105 |
# File 'lib/vnehm/command.rb', line 102 def add_option(option, usage, desc) @options[option] = nil @options_descs[usage] = desc end |
#arguments ⇒ Object
Override to provide details of the arguments a command takes
For example:
def usage
"#{program_name} COMMAND"
end
def arguments
['COMMAND', 'name of command to show help']
end
71 72 73 |
# File 'lib/vnehm/command.rb', line 71 def arguments {} end |
#execute ⇒ Object
Override to provide command handling
#options will be filled in with your parsed options, unparsed options will be left in #options
55 56 |
# File 'lib/vnehm/command.rb', line 55 def execute end |
#handle_options(args) ⇒ Object
Handle the given list of arguments by parsing them and recording the results
44 45 46 47 |
# File 'lib/vnehm/command.rb', line 44 def (args) parser = OptionParser.new(args, self) parser.parse end |
#invoke(args) ⇒ Object
Invoke the command with the given list of arguments
35 36 37 38 |
# File 'lib/vnehm/command.rb', line 35 def invoke(args) (args) execute end |
#program_name ⇒ Object
The name of the command for command-line invocation
78 79 |
# File 'lib/vnehm/command.rb', line 78 def program_name end |
#summary ⇒ Object
Override to display a short description of what this command does
84 85 |
# File 'lib/vnehm/command.rb', line 84 def summary end |
#usage ⇒ Object
Override to display the usage for an individual vnehm command
The text “[options]” is automatically appended to the usage text
92 93 |
# File 'lib/vnehm/command.rb', line 92 def usage end |