lib/support/help.rb in gli-1.2.6 vs lib/support/help.rb in gli-1.3.0

- old
+ new

@@ -3,13 +3,28 @@ require 'gli/terminal' module GLI class DefaultHelpCommand < Command #:nodoc: @@output = $stdout + @@skips_pre = true + @@skips_post = true + # Exposed for testing def self.output_device=(o); @@output = o; end + # To override the default behavior of the help command, which is + # to NOT run the pre block, use this. + def self.skips_pre=(skips_pre) + @@skips_pre = skips_pre + end + + # To override the default behavior of the help command, which is + # to NOT run the post block, use this. + def self.skips_post=(skips_post) + @@skips_post = skips_post + end + 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', @@ -17,10 +32,13 @@ '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 + def skips_pre; @@skips_pre; end + def skips_post; @@skips_post; end + def execute(global_options,options,arguments) if options[:c] names = commands_to_show.reduce([]) do |memo,obj| memo << obj[0] memo << obj[1].aliases @@ -45,9 +63,13 @@ end private def list_global_flags + if GLI.program_desc + @@output.puts wrap(GLI.program_desc,0) + @@output.puts + end usage = "usage: #{GLI.program_name} " all_options = GLI.switches.merge(GLI.flags) if !all_options.empty? usage += "[global options] " end