Module: Climate::Script
- Includes:
- ParsingMethods
- Defined in:
- lib/climate/script.rb
Overview
Module that you can extend any object with to turn it in to a climate script. See the readme for intended usage, but follows the same pattern as the command, with the exception that it does not allow subcommands
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#leftovers ⇒ Object
readonly
Returns the value of attribute leftovers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #ancestors ⇒ Object
- #command_name ⇒ Object
-
#description(string = nil) ⇒ Object
Set the description for this script.
- #has_subcommands? ⇒ Boolean
- #parse_argv ⇒ Object
Methods included from ParsingMethods
#arg, #cli_arguments, #cli_options, #conflicting_options, #conflicts, #dependent_options, #depends, #has_argument?, #has_arguments?, #has_multi_argument?, #has_options?, #has_required_argument?, #opt, #parse, #parse_arguments, #stop_on, #trollop_parser
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
39 40 41 |
# File 'lib/climate/script.rb', line 39 def arguments @arguments end |
#leftovers ⇒ Object (readonly)
Returns the value of attribute leftovers.
39 40 41 |
# File 'lib/climate/script.rb', line 39 def leftovers @leftovers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
39 40 41 |
# File 'lib/climate/script.rb', line 39 def @options end |
Class Method Details
.extended(othermodule) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/climate/script.rb', line 8 def self.extended(othermodule) if @included.nil? @included = true at_exit do Climate.with_standard_exception_handling do begin othermodule.send(:parse_argv) rescue Trollop::HelpNeeded => e raise HelpNeeded.new(othermodule) end othermodule.send(:run) end end end end |
Instance Method Details
#ancestors ⇒ Object
41 |
# File 'lib/climate/script.rb', line 41 def ancestors ; [self] ; end |
#command_name ⇒ Object
42 |
# File 'lib/climate/script.rb', line 42 def command_name ; File.basename($CLIMATE_PROGRAM_NAME || $PROGRAM_NAME) ; end |
#description(string = nil) ⇒ Object
Set the description for this script
27 28 29 30 31 32 33 |
# File 'lib/climate/script.rb', line 27 def description(string=nil) if string.nil? @description else @description = string end end |
#has_subcommands? ⇒ Boolean
44 |
# File 'lib/climate/script.rb', line 44 def has_subcommands? ; false ; end |
#parse_argv ⇒ Object
35 36 37 |
# File 'lib/climate/script.rb', line 35 def parse_argv @arguments, @options, @leftovers = self.parse(ARGV) end |