Skip to content

Commit 96a3974

Browse files
authored
Merge pull request #876 from andrewn617/improve-boolean-parse-documentation
Document the '--skip-' option for boolean options.
2 parents e43a9cd + 686bcd5 commit 96a3974

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

lib/thor/parser/option.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def usage(padding = 0)
8989

9090
sample = "[#{sample}]".dup unless required?
9191

92-
if boolean?
93-
sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.match(/\Ano[\-_]/)
92+
if boolean? && name != "force" && !name.match(/\A(no|skip)[\-_]/)
93+
sample << ", [#{dasherize('no-' + human_name)}], [#{dasherize('skip-' + human_name)}]"
9494
end
9595

9696
aliases_for_usage.ljust(padding) + sample

lib/thor/parser/options.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ def parsing_options?
250250
@parsing_options
251251
end
252252

253-
# Parse boolean values which can be given as --foo=true, --foo or --no-foo.
253+
# Parse boolean values which can be given as --foo=true or --foo for true values, or
254+
# --foo=false, --no-foo or --skip-foo for false values.
254255
#
255256
def parse_boolean(switch)
256257
if current_is_value?

spec/parser/option_spec.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ def option(name, options = {})
218218
end
219219

220220
it "returns usage for boolean types" do
221-
expect(parse(:foo, :boolean).usage).to eq("[--foo], [--no-foo]")
221+
expect(parse(:foo, :boolean).usage).to eq("[--foo], [--no-foo], [--skip-foo]")
222222
end
223223

224224
it "does not use padding when no aliases are given" do
225-
expect(parse(:foo, :boolean).usage).to eq("[--foo], [--no-foo]")
225+
expect(parse(:foo, :boolean).usage).to eq("[--foo], [--no-foo], [--skip-foo]")
226226
end
227227

228228
it "documents a negative option when boolean" do
@@ -231,6 +231,9 @@ def option(name, options = {})
231231

232232
it "does not document a negative option for a negative boolean" do
233233
expect(parse(:'no-foo', :boolean).usage).not_to include("[--no-no-foo]")
234+
expect(parse(:'no-foo', :boolean).usage).not_to include("[--skip-no-foo]")
235+
expect(parse(:'skip-foo', :boolean).usage).not_to include("[--no-skip-foo]")
236+
expect(parse(:'skip-foo', :boolean).usage).not_to include("[--skip-skip-foo]")
234237
end
235238

236239
it "does not document a negative option for an underscored negative boolean" do
@@ -261,7 +264,7 @@ def option(name, options = {})
261264
end
262265

263266
it "does not negate the aliases" do
264-
expect(parse([:foo, "-f", "-b"], :boolean).usage).to eq("-f, -b, [--foo], [--no-foo]")
267+
expect(parse([:foo, "-f", "-b"], :boolean).usage).to eq("-f, -b, [--foo], [--no-foo], [--skip-foo]")
265268
end
266269

267270
it "normalizes the aliases" do

0 commit comments

Comments
 (0)