lib/gli/app_support.rb in gli-2.6.1 vs lib/gli/app_support.rb in gli-2.6.2

- old
+ new

@@ -59,11 +59,11 @@ args = args.dup if @preserve_argv the_command = nil begin override_defaults_based_on_config(parse_config) - add_help_switch_if_needed(switches) + add_help_switch_if_needed(self) gli_option_parser = GLIOptionParser.new(commands, flags, switches, accepts, @@ -77,11 +77,11 @@ if proceed?(parsing_result) call_command(parsing_result) 0 else - exit_now!(nil,65) + raise PreconditionFailed, "preconditions failed" end rescue Exception => ex if the_command.nil? && ex.respond_to?(:command_in_context) the_command = ex.command_in_context end @@ -229,18 +229,16 @@ def no_message_given?(ex) ex.message == ex.class.name end - def add_help_switch_if_needed(switches) - help_switch_exists = switches.values.find { |switch| - (Array(switch.aliases) + [switch.name]).find { |an_alias| - an_alias.to_s == 'help' - } + def add_help_switch_if_needed(target) + help_switch_exists = target.switches.values.find { |switch| + switch.names_and_aliases.map(&:to_s).find { |an_alias| an_alias == 'help' } } unless help_switch_exists - desc 'Show this message' - switch :help, :negatable => false + target.desc 'Show this message' + target.switch :help, :negatable => false end end # True if we should proceed with executing the command; this calls # the pre block if it's defined