Skip to content

Commit

Permalink
Output validations when help is invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmeyer committed May 13, 2015
1 parent cfa5eca commit 9e17008
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/thor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ def print_options(shell, options, group_name = nil)
list << item
list << ["", "# Default: #{option.default}"] if option.show_default?
list << ["", "# Possible values: #{option.enum.join(', ')}"] if option.enum
list << ["", "# Validation: #{option.validator_description}"] if option.validator_description
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/script.thor
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ END
[name, options, args]
end

method_option :my_option, :type => :string, :validator => proc { |v| v == 'hello world' }, :validator_desc => 'Needs to be "hello world"'
desc 'with_validator', 'Check option with validator'
def with_validator
[options]
end

class AnotherScript < Thor
desc "baz", "do some bazing"
def baz
Expand Down
4 changes: 4 additions & 0 deletions spec/thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ def shell
END
end

it "outputs information about validations as well" do
expect(capture(:stdout) { MyScript.command_help(shell, "with_validator") }).to include 'Validation'
end

it "raises an error if the command can't be found" do
expect do
MyScript.command_help(shell, "unknown")
Expand Down

0 comments on commit 9e17008

Please sign in to comment.