diff --git a/lib/thor/base.rb b/lib/thor/base.rb index cf3935822..7b9ecf8d5 100644 --- a/lib/thor/base.rb +++ b/lib/thor/base.rb @@ -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 diff --git a/spec/fixtures/script.thor b/spec/fixtures/script.thor index 6ea1c1e71..4b516d551 100644 --- a/spec/fixtures/script.thor +++ b/spec/fixtures/script.thor @@ -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 diff --git a/spec/thor_spec.rb b/spec/thor_spec.rb index 55450dc25..ecfd2ff50 100644 --- a/spec/thor_spec.rb +++ b/spec/thor_spec.rb @@ -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")