Class: GLI::DefaultHelpCommand
- Inherits:
-
Command
- Object
- CommandLineToken
- Command
- GLI::DefaultHelpCommand
- Defined in:
- lib/support/help.rb
Overview
:nodoc:
Constant Summary collapse
- @@output =
$stdout
- @@skips_pre =
true
- @@skips_post =
true
Instance Attribute Summary
Attributes inherited from CommandLineToken
#aliases, #description, #long_description, #name
Class Method Summary collapse
-
.output_device=(o) ⇒ Object
Exposed for testing.
-
.skips_post=(skips_post) ⇒ Object
To override the default behavior of the help command, which is to NOT run the post block, use this.
-
.skips_pre=(skips_pre) ⇒ Object
To override the default behavior of the help command, which is to NOT run the pre block, use this.
Instance Method Summary collapse
- #execute(global_options, options, arguments) ⇒ Object
-
#initialize(version, *omit_from_list) ⇒ DefaultHelpCommand
constructor
A new instance of DefaultHelpCommand.
- #skips_post ⇒ Object
- #skips_pre ⇒ Object
Methods inherited from Command
#action, #arg_name, #arguments_description, #clear_nexts, #default_value, #desc, #flag, #flags, #long_desc, name_as_string, #names, #switch, #switches, #usage
Methods included from CopyOptionsToAliases
Methods inherited from CommandLineToken
Constructor Details
#initialize(version, *omit_from_list) ⇒ DefaultHelpCommand
Returns a new instance of DefaultHelpCommand.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/support/help.rb', line 26 def initialize(version,*omit_from_list) @omit_from_list = omit_from_list @version = version super(:help, 'Shows list of commands or help for one command', '[command]', 'Gets help for the application or its commands. Can also list the commands in a way helpful to creating a bash-style completion function') self.desc 'List all commands one line at a time, for use with shell completion ([command] argument is partial command to match)' self.switch [:c,:completion] end |
Class Method Details
.output_device=(o) ⇒ Object
Exposed for testing
12 |
# File 'lib/support/help.rb', line 12 def self.output_device=(o); @@output = o; end |
.skips_post=(skips_post) ⇒ Object
To override the default behavior of the help command, which is to NOT run the post block, use this.
22 23 24 |
# File 'lib/support/help.rb', line 22 def self.skips_post=(skips_post) @@skips_post = skips_post end |
.skips_pre=(skips_pre) ⇒ Object
To override the default behavior of the help command, which is to NOT run the pre block, use this.
16 17 18 |
# File 'lib/support/help.rb', line 16 def self.skips_pre=(skips_pre) @@skips_pre = skips_pre end |
Instance Method Details
#execute(global_options, options, arguments) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/support/help.rb', line 40 def execute(,,arguments) if [:c] names = commands_to_show.reduce([]) do |memo,obj| memo << obj[0] memo << obj[1].aliases memo = memo.flatten end names.map! { |name| name.to_s } if arguments && arguments.size > 0 names = names.select { |name| name =~ /^#{arguments[0]}/ } end names.sort.each do |command| next if command.empty? @@output.puts command end else if arguments.empty? list_global_flags list_commands else list_one_command_help(arguments[0]) end end end |
#skips_post ⇒ Object
38 |
# File 'lib/support/help.rb', line 38 def skips_post; @@skips_post; end |
#skips_pre ⇒ Object
37 |
# File 'lib/support/help.rb', line 37 def skips_pre; @@skips_pre; end |