Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Default opt type is now a boolean flag.

  • Loading branch information...
commit 3377cf70f5cd821c9da9b4f4e0595d715041c15d 1 parent dff532a
@relistan authored
Showing with 5 additions and 5 deletions.
  1. +4 −4 spec/options.spec.coffee
  2. +1 −1  src/troll.coffee
View
8 spec/options.spec.coffee
@@ -84,6 +84,10 @@ describe 'Options', ->
@opts.opt 'silent', 'Enable silent mode', default: false
expect(@opts.getParsedOpts().silent.type).toEqual 'boolean'
+ it 'set the type to boolean when neither type nor default are set', ->
+ @opts.opt 'header', 'Add a header', required: true
+ expect(@opts.getParsedOpts().header.type).toEqual 'boolean'
+
it 'raises when the type was set and a default was provided', ->
expect( =>
@opts.opt 'header', 'Add a header', default: 'X-Something', type: 'string'
@@ -92,10 +96,6 @@ describe 'Options', ->
it 'raises when no options are set', ->
expect( => @opts.opt 'header', 'Add a header' ).toThrow('No options were set')
- it 'raises when neither type nor default are set', ->
- expect( => @opts.opt 'header', 'Add a header', required: true ).toThrow(
- 'Neither default nor type is set for \'header\'')
-
it 'raises when unknown settings are passed', ->
expect( => @opts.opt 'header', 'Add a header', type: 'boolean', asdf: true ).toThrow(
'Unrecognized options \'asdf\'')
View
2  src/troll.coffee
@@ -130,7 +130,7 @@ class Options
throw new TrollOptError('No options were set') if _.isUndefined(opts)
unless _.has(opts, 'default') or _.has(opts, 'type')
- throw new TrollOptError("Neither default nor type is set for '#{name}'")
+ opts['type'] = 'boolean'
if _.has(opts, 'default') and _.has(opts, 'required')
throw new TrollOptError("Can't define both default and required on '#{name}'")
Please sign in to comment.
Something went wrong with that request. Please try again.