From e5615fbdd7c4cd07e8fb0c1109fc6da56981829f Mon Sep 17 00:00:00 2001 From: Lee Jarvis Date: Fri, 10 Jul 2020 08:36:54 +0100 Subject: Fix bug with separators around `help: false` opts The separators rely on the indexes of the options before/after them, but we ignore `help: false` options when building the help string, so all of the positions are messed up. This change avoids ignoring those options during the iteration, and instead just doesn't append the option help to the string. Fixes #253 --- lib/slop/options.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/slop/options.rb b/lib/slop/options.rb index 9a5f5cc..875fcfe 100644 --- a/lib/slop/options.rb +++ b/lib/slop/options.rb @@ -102,13 +102,13 @@ module Slop str = config[:banner] ? "#{banner}\n" : "" len = longest_flag_length - options.select(&:help?).each_with_index.sort_by{ |o,i| [o.tail, i] }.each do |opt, i| + options.select.each_with_index.sort_by{ |o,i| [o.tail, i] }.each do |opt, i| # use the index to fetch an associated separator if sep = separators[i] str << "#{sep}\n" end - str << "#{prefix}#{opt.to_s(offset: len)}\n" + str << "#{prefix}#{opt.to_s(offset: len)}\n" if opt.help? end if sep = separators[options.size] -- cgit v1.2.1