Skip to content
This repository was archived by the owner on Jul 28, 2018. It is now read-only.

Commit cda99bd

Browse files
committed
commit for v1.1.0
1 parent 84cc159 commit cda99bd

File tree

410 files changed

+68980
-26925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+68980
-26925
lines changed

Diff for: src/github.com/docopt/docopt-go/.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@ language: go
77
go:
88
- 1.4
99
- 1.5
10+
- 1.6
11+
- 1.7
12+
- 1.8
13+
- 1.9
1014
- tip
1115

1216
matrix:
1317
fast_finish: true
1418

1519
before_install:
16-
- go get golang.org/x/tools/cmd/vet
1720
- go get golang.org/x/tools/cmd/cover
18-
- go get github.com/golang/lint/golint
1921
- go get github.com/mattn/goveralls
2022

2123
install:
2224
- go get -d -v ./... && go build -v ./...
2325

2426
script:
2527
- go vet -x ./...
26-
- $HOME/gopath/bin/golint ./...
2728
- go test -v ./...
2829
- go test -covermode=count -coverprofile=profile.cov .
2930

Diff for: src/github.com/docopt/docopt-go/LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2013 Keith Batten
4+
Copyright (c) 2016 David Irvine
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy of
67
this software and associated documentation files (the "Software"), to deal in

Diff for: src/github.com/docopt/docopt-go/README.md

+54-26
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ docopt-go
22
=========
33

44
[![Build Status](https://travis-ci.org/docopt/docopt.go.svg?branch=master)](https://travis-ci.org/docopt/docopt.go)
5-
[![Coverage Status](https://coveralls.io/repos/docopt/docopt.go/badge.png)](https://coveralls.io/r/docopt/docopt.go)
6-
[![GoDoc](https://godoc.org/github.com/docopt/docopt.go?status.png)](https://godoc.org/github.com/docopt/docopt.go)
5+
[![Coverage Status](https://coveralls.io/repos/github/docopt/docopt.go/badge.svg)](https://coveralls.io/github/docopt/docopt.go)
6+
[![GoDoc](https://godoc.org/github.com/docopt/docopt.go?status.svg)](https://godoc.org/github.com/docopt/docopt.go)
77

8-
An implementation of [docopt](http://docopt.org/) in the
9-
[Go](http://golang.org/) programming language.
8+
An implementation of [docopt](http://docopt.org/) in the [Go](http://golang.org/) programming language.
109

1110
**docopt** helps you create *beautiful* command-line interfaces easily:
1211

@@ -36,53 +35,82 @@ Options:
3635
--moored Moored (anchored) mine.
3736
--drifting Drifting mine.`
3837

39-
arguments, _ := docopt.Parse(usage, nil, true, "Naval Fate 2.0", false)
38+
arguments, _ := docopt.ParseDoc(usage)
4039
fmt.Println(arguments)
4140
}
4241
```
4342

44-
**docopt** parses command-line arguments based on a help message. Don't
45-
write parser code: a good help message already has all the necessary
46-
information in it.
43+
**docopt** parses command-line arguments based on a help message. Don't write parser code: a good help message already has all the necessary information in it.
4744

4845
## Installation
4946

50-
⚠ Use the alias docopt-go. To use docopt in your Go code:
47+
⚠ Use the alias "docopt-go". To use docopt in your Go code:
5148

5249
```go
5350
import "github.com/docopt/docopt-go"
5451
```
5552

56-
To install docopt according to your `$GOPATH`:
53+
To install docopt in your `$GOPATH`:
5754

5855
```console
5956
$ go get github.com/docopt/docopt-go
6057
```
6158

6259
## API
6360

61+
Given a conventional command-line help message, docopt processes the arguments. See https://github.com/docopt/docopt#help-message-format for a description of the help message format.
62+
63+
This package exposes three different APIs, depending on the level of control required. The first, simplest way to parse your docopt usage is to just call:
64+
65+
```go
66+
docopt.ParseDoc(usage)
67+
```
68+
69+
This will use `os.Args[1:]` as the argv slice, and use the default parser options. If you want to provide your own version string and args, then use:
70+
6471
```go
65-
func Parse(doc string, argv []string, help bool, version string,
66-
optionsFirst bool, exit ...bool) (map[string]interface{}, error)
72+
docopt.ParseArgs(usage, argv, "1.2.3")
73+
```
74+
75+
If the last parameter (version) is a non-empty string, it will be printed when `--version` is given in the argv slice. Finally, we can instantiate our own `docopt.Parser` which gives us control over how things like help messages are printed and whether to exit after displaying usage messages, etc.
76+
77+
```go
78+
parser := &docopt.Parser{
79+
HelpHandler: docopt.PrintHelpOnly,
80+
OptionsFirst: true,
81+
}
82+
opts, err := parser.ParseArgs(usage, argv, "")
83+
```
84+
85+
In particular, setting your own custom `HelpHandler` function makes unit testing your own docs with example command line invocations much more enjoyable.
86+
87+
All three of these return a map of option names to the values parsed from argv, and an error or nil. You can get the values using the helpers, or just treat it as a regular map:
88+
89+
```go
90+
flag, _ := opts.Bool("--flag")
91+
secs, _ := opts.Int("<seconds>")
92+
```
93+
94+
Additionally, you can `Bind` these to a struct, assigning option values to the
95+
exported fields of that struct, all at once.
96+
97+
```go
98+
var config struct {
99+
Command string `docopt:"<cmd>"`
100+
Tries int `docopt:"-n"`
101+
Force bool // Gets the value of --force
102+
}
103+
opts.Bind(&config)
67104
```
68-
Parse `argv` based on the command-line interface described in `doc`.
69105

70-
Given a conventional command-line help message, docopt creates a parser and
71-
processes the arguments. See
72-
https://github.com/docopt/docopt#help-message-format for a description of the
73-
help message format. If `argv` is `nil`, `os.Args[1:]` is used.
106+
More documentation is available at [godoc.org](https://godoc.org/github.com/docopt/docopt-go).
74107

75-
docopt returns a map of option names to the values parsed from `argv`, and an
76-
error or `nil`.
108+
## Unit Testing
77109

78-
More documentation for docopt is available at
79-
[GoDoc.org](https://godoc.org/github.com/docopt/docopt.go).
110+
Unit testing your own usage docs is recommended, so you can be sure that for a given command line invocation, the expected options are set. An example of how to do this is [in the examples folder](examples/unit_test/unit_test.go).
80111

81-
## Testing
112+
## Tests
82113

83-
All tests from the Python version are implemented and passing
84-
at [Travis CI](https://travis-ci.org/docopt/docopt.go). New
85-
language-agnostic tests have been added
86-
to [test_golang.docopt](test_golang.docopt).
114+
All tests from the Python version are implemented and passing at [Travis CI](https://travis-ci.org/docopt/docopt-go). New language-agnostic tests have been added to [test_golang.docopt](test_golang.docopt).
87115

88116
To run tests for docopt-go, use `go test`.

Diff for: src/github.com/docopt/docopt-go/doc.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Package docopt parses command-line arguments based on a help message.
3+
4+
Given a conventional command-line help message, docopt processes the arguments.
5+
See https://github.com/docopt/docopt#help-message-format for a description of
6+
the help message format.
7+
8+
This package exposes three different APIs, depending on the level of control
9+
required. The first, simplest way to parse your docopt usage is to just call:
10+
11+
docopt.ParseDoc(usage)
12+
13+
This will use os.Args[1:] as the argv slice, and use the default parser
14+
options. If you want to provide your own version string and args, then use:
15+
16+
docopt.ParseArgs(usage, argv, "1.2.3")
17+
18+
If the last parameter (version) is a non-empty string, it will be printed when
19+
--version is given in the argv slice. Finally, we can instantiate our own
20+
docopt.Parser which gives us control over how things like help messages are
21+
printed and whether to exit after displaying usage messages, etc.
22+
23+
parser := &docopt.Parser{
24+
HelpHandler: docopt.PrintHelpOnly,
25+
OptionsFirst: true,
26+
}
27+
opts, err := parser.ParseArgs(usage, argv, "")
28+
29+
In particular, setting your own custom HelpHandler function makes unit testing
30+
your own docs with example command line invocations much more enjoyable.
31+
32+
All three of these return a map of option names to the values parsed from argv,
33+
and an error or nil. You can get the values using the helpers, or just treat it
34+
as a regular map:
35+
36+
flag, _ := opts.Bool("--flag")
37+
secs, _ := opts.Int("<seconds>")
38+
39+
Additionally, you can `Bind` these to a struct, assigning option values to the
40+
exported fields of that struct, all at once.
41+
42+
var config struct {
43+
Command string `docopt:"<cmd>"`
44+
Tries int `docopt:"-n"`
45+
Force bool // Gets the value of --force
46+
}
47+
opts.Bind(&config)
48+
*/
49+
package docopt

0 commit comments

Comments
 (0)