summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2015-01-02 16:59:11 +0000
committerLee Jarvis <ljjarvis@gmail.com>2015-01-02 16:59:11 +0000
commit4057bcf675147ac0c39306a7b74a7996f102a191 (patch)
treed43c55d1e8c54480c860c25d1a584c313e5c73e1 /lib
parenteb0164aea27b43f24c05e16c3d699dac520c9945 (diff)
downloadslop-4057bcf675147ac0c39306a7b74a7996f102a191.tar.gz
Support `tail: true` config option
Diffstat (limited to 'lib')
-rw-r--r--lib/slop/option.rb14
-rw-r--r--lib/slop/options.rb2
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/slop/option.rb b/lib/slop/option.rb
index 5dc8156..218dc90 100644
--- a/lib/slop/option.rb
+++ b/lib/slop/option.rb
@@ -1,7 +1,8 @@
module Slop
class Option
DEFAULT_CONFIG = {
- help: true
+ help: true,
+ tail: false,
}
# An Array of flags this option matches.
@@ -109,6 +110,17 @@ module Slop
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]
diff --git a/lib/slop/options.rb b/lib/slop/options.rb
index bb0112b..ed99c64 100644
--- a/lib/slop/options.rb
+++ b/lib/slop/options.rb
@@ -101,7 +101,7 @@ module Slop
str = config[:banner] ? "#{banner}\n" : ""
len = longest_flag_length
- options.select(&:help?).each_with_index do |opt, i|
+ options.select(&:help?).sort_by(&:tail).each_with_index do |opt, i|
# use the index to fetch an associated separator
if sep = separators[i]
str << "#{sep}\n"