Skip to content

Instantly share code, notes, and snippets.

@ensonic
Last active August 29, 2015 14:20
Show Gist options
  • Save ensonic/5a4d727cbc6f5fc36655 to your computer and use it in GitHub Desktop.
Save ensonic/5a4d727cbc6f5fc36655 to your computer and use it in GitHub Desktop.
commander pitfalls, try coffee ./test.coffee --flag1 false
#!/usr/bin/env node
program = require 'commander'
program
.option('--flag1 [true/false]', 'Flag1 (default = false)', false)
.option('--flag2 [true/false]', 'Flag2 (default = false)', ((val) -> (val is "true")), false)
.parse process.argv
# value is a string if given
if program.flag1
console.log "flag1(#{typeof program.flag1}) is true"
else
console.log "flag1(#{typeof program.flag1}) is false"
# value is converted to a boolean
if program.flag2
console.log "flag2(#{typeof program.flag2}) is true"
else
console.log "flag2(#{typeof program.flag2}) is false"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment