lib/slop/option.rb in slop-4.0.0 vs lib/slop/option.rb in slop-4.1.0
- old
+ new
@@ -1,9 +1,10 @@
module Slop
class Option
DEFAULT_CONFIG = {
- help: true
+ help: true,
+ tail: false,
}
# An Array of flags this option matches.
attr_reader :flags
@@ -45,11 +46,11 @@
# It's used in the Parser.
def ensure_call(value)
@count += 1
if value.nil? && expects_argument? && !suppress_errors?
- raise Slop::MissingArgument, "missing argument for #{flag}"
+ raise Slop::MissingArgument.new("missing argument for #{flag}", flags)
end
@value = call(value)
block.call(@value) if block.respond_to?(:call)
end
@@ -105,9 +106,20 @@
end
# Returns true if this option should be displayed in help text.
def help?
config[:help]
+ end
+
+ # Returns true if this option should be added to the tail of the help text.
+ def tail?
+ config[:tail]
+ end
+
+ # Returns 1 if this option should be added to the tail of the help text.
+ # Used for sorting.
+ def tail
+ tail? ? 1 : -1
end
# Returns the help text for this option (flags and description).
def to_s(offset: 0)
"%-#{offset}s %s" % [flag, desc]