Class: CmdParse::VersionCommand
- Defined in:
- lib/module_cmdparse/cmdparse.rb
Overview
The default version command. It adds the options “-v” and “–version” to the global options of the associated CommandParser. When specified on the command line, it shows the version of the program.
Instance Attribute Summary
Attributes inherited from Command
#commands, #default_command, #description, #name, #options, #pen, #short_desc, #super_command
Instance Method Summary collapse
- #execute(args) ⇒ Object
- #init ⇒ Object
-
#initialize(_pen = $stdout) ⇒ VersionCommand
constructor
A new instance of VersionCommand.
- #usage ⇒ Object
Methods inherited from Command
#<=>, #add_command, #commandparser, #has_commands?, #set_execution_block, #show_help, #super_commands, #use_partial_commands
Constructor Details
#initialize(_pen = $stdout) ⇒ VersionCommand
Returns a new instance of VersionCommand.
349 350 351 352 353 |
# File 'lib/module_cmdparse/cmdparse.rb', line 349 def initialize(_pen = $stdout) super( 'version', false ) self.short_desc = "Show the version of the program" @pen = _pen end |
Instance Method Details
#execute(args) ⇒ Object
370 371 372 373 374 375 |
# File 'lib/module_cmdparse/cmdparse.rb', line 370 def execute( args ) version = commandparser.program_version version = version.join( '.' ) if version.instance_of?( Array ) @pen.puts commandparser. + "\n" if commandparser. @pen.puts version end |
#init ⇒ Object
355 356 357 358 359 360 361 362 363 364 |
# File 'lib/module_cmdparse/cmdparse.rb', line 355 def init case commandparser.main_command. when OptionParserWrapper commandparser.main_command..instance do |opt| opt.on_tail( "--version", "-v", "Show the version of the program" ) do execute( [] ) end end end end |
#usage ⇒ Object
366 367 368 |
# File 'lib/module_cmdparse/cmdparse.rb', line 366 def usage "#{@pen.bold}Usage#{@pen.bold}: #{@pen.lightcyan}#{commandparser.program_name} version#{@pen.clear}" end |