commit | 4dcfb5a0ed427b216ce6050d7f9ab7e1e53d8cef | [log] [tgz] |
---|---|---|
author | Keith Batten <kbatten@gmail.com> | Sat Sep 07 12:19:09 2013 -0700 |
committer | Keith Batten <kbatten@gmail.com> | Sat Sep 07 12:19:09 2013 -0700 |
tree | 39a88eb887a0048cd3b358176aa5908048dc5714 | |
parent | eac2c0a03e3a94924691145f3e93c103f51dbc71 [diff] |
set test args to be empty, not nil if nil, the args will grab from os.Args which isn't what we want here
Golang implementation of docopt 0.6.1+fix
import “github.com/docopt/docopt.go” and then run go get
.
These may be updated because it seems like a cumbersome way to get around optional parameters
func docopt.Parse(doc string, argv []string, help bool, version string, optionsFirst bool)
(args map[string]interface{}, output string, err error)
func docopt.ParseEasy(doc string)
args map[string]interface{}
func docopt.ParseLoud(doc string, argv []string, help bool, version string, optionsFirst bool)
args map[string]interface{}
func docopt.ParseQuiet(doc string, argv []string, help bool, version string, optionsFirst bool)
(args map[string]interface{}, err error)
doc
, usage string based on docopt language.
argv
, optional argument vector. set to nil
to use os.Args.
help
, set to true
to have docopt automatically handle -h
and --help
.
version
, set to a non-empty string that will automatically be shown with --version
.
optionsFirst
, set to true
to disallow mixing options and positional arguments.
args
, map[string]interface{}. interface{} can be bool
, int
, string
, []string
.
output
, help output that would normally be displayed by the other docopt.Parse*
functions.
err
nil
, no error*docopt.UserError
, user argument error*docopt.LanguageError
, developer errorpackage main
import (
"fmt"
docopt "github.com/docopt/docopt.go"
)
func main() {
usage := `Naval Fate.
Usage:
naval_fate ship new <name>...
naval_fate ship <name> move <x> <y> [--speed=<kn>]
naval_fate ship shoot <x> <y>
naval_fate mine (set|remove) <x> <y> [--moored|--drifting]
naval_fate -h | --help
naval_fate --version
Options:
-h --help Show this screen.
--version Show version.
--speed=<kn> Speed in knots [default: 10].
--moored Moored (anchored) mine.
--drifting Drifting mine.`
arguments := docopt.ParseLoud(usage, nil, true, "Naval Fate 2.0", false)
fmt.Println(arguments)
}
All tests from the python version have been implemented and all are passing.
New language agnostic tests have been added to test_golang.docopt
.
To run them use go test
.