Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/dredd/rack/runner.rb

Instance Method Summary collapse

Instance Method Details

#has_at_least_two_arguments?Boolean

Verify that a command has at least two arguments (excluding options)

Examples:

"dredd doc/*.apib http://api.example.com".valid? # => true
"dredd doc/*.apib doc/*apib.md http://api.example.com".valid? # => true
"dredd doc/*.apib http://api.example.com --level verbose".valid? # => true
"dredd http://api.example.com".valid? # => false
"dredd doc/*.apib --dry-run".valid? # => false
"dredd --dry-run --level verbose".valid? # => false

Known limitations:

Does not support short flags. (e.g. using -l instead of --level). Requires options to be specified after the last argument.

Note:

The known limitations imply that there may be false negatives: this method can return false for commands that do have two arguments or more. But there should not be false positives: if the method returns true, then the command does have at least two arguments.

Returns true if the command String has at least two arguments, false otherwise.

Returns:

  • (Boolean)


161
162
163
# File 'lib/dredd/rack/runner.rb', line 161

def has_at_least_two_arguments?
  split('--').first.split(' ').length >= 3
end