cli flags


Node.js

  1. const yargs = require('yargs')
  2. const { foo='default value', qux=false } = yargs.argv
  3. console.log('foo:', foo)
  4. console.log('qux:', qux)

Output

  1. $ node examples/cli_flags.js --foo='bar' --qux=true
  2. foo: bar
  3. qux: true

Go

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. )
  6. func main() {
  7. var foo string
  8. flag.StringVar(&foo, "foo", "default value", "a string var")
  9. var qux bool
  10. flag.BoolVar(&qux, "qux", false, "a bool var")
  11. flag.Parse()
  12. fmt.Println("foo:", foo)
  13. fmt.Println("qux:", qux)
  14. }

Output

  1. $ go run examples/cli_flags.go -foo='bar' -qux=true
  2. foo: bar
  3. qux: true