Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle conversion to encoding.TextUnmarshaler #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ _testmain.go

# coverage droppings
profile.cov
/*.test
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
docopt-go
=========

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

An implementation of [docopt](http://docopt.org/) in the [Go](http://golang.org/) programming language.

Expand All @@ -14,7 +14,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down Expand Up @@ -47,13 +47,13 @@ Options:
⚠ Use the alias "docopt-go". To use docopt in your Go code:

```go
import "github.com/docopt/docopt-go"
import "github.com/kovetskiy/docopt-go"
```

To install docopt in your `$GOPATH`:

```console
$ go get github.com/docopt/docopt-go
$ go get github.com/kovetskiy/docopt-go
```

## API
Expand Down Expand Up @@ -103,14 +103,14 @@ var config struct {
opts.Bind(&config)
```

More documentation is available at [godoc.org](https://godoc.org/github.com/docopt/docopt-go).
More documentation is available at [godoc.org](https://godoc.org/github.com/kovetskiy/docopt-go).

## Unit Testing

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).

## Tests

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).
All tests from the Python version are implemented and passing at [Travis CI](https://travis-ci.org/kovetskiy/docopt-go). New language-agnostic tests have been added to [test_golang.docopt](test_golang.docopt).

To run tests for docopt-go, use `go test`.
24 changes: 19 additions & 5 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package docopt

import (
"fmt"
"net"
"sort"
)

Expand Down Expand Up @@ -40,10 +41,17 @@ func ExampleParseArgs() {
}

func ExampleOpts_Bind() {
usage := `Usage:
example tcp [<host>...] [--force] [--timeout=<seconds>]
usage := `docopt-go example

Usage:
example tcp [<host>...] [--force] [--timeout=<seconds>] [--gateway=<ip>]
example serial <port> [--baud=<rate>] [--timeout=<seconds>]
example --help | --version`
example --help | --version

Options:
--gateway <ip> Set the gateway IP address [default: 192.168.0.1]
-h --help Show this screen.
`

// Parse the command line `example serial 443 --baud=9600`
argv := []string{"serial", "443", "--baud=9600"}
Expand All @@ -57,13 +65,19 @@ func ExampleOpts_Bind() {
Force bool
Timeout int
Baud int
Gateway net.IP
}
opts.Bind(&conf)

if conf.Serial {
fmt.Printf("port: %d, baud: %d", conf.Port, conf.Baud)
fmt.Printf(
"port: %d, baud: %d, gateway: %v",
conf.Port,
conf.Baud,
conf.Gateway,
)
}

// Output:
// port: 443, baud: 9600
// port: 443, baud: 9600, gateway: 192.168.0.1
}
2 changes: 1 addition & 1 deletion examples/arguments/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

var usage = `Usage: arguments [-vqrh] [FILE] ...
Expand Down
2 changes: 1 addition & 1 deletion examples/arguments/arguments_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/docopt/docopt-go/examples"
"github.com/kovetskiy/docopt-go/examples"
)

func Example() {
Expand Down
2 changes: 1 addition & 1 deletion examples/calculator/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

var usage = `Not a serious example.
Expand Down
2 changes: 1 addition & 1 deletion examples/calculator/calculator_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/docopt/docopt-go/examples"
"github.com/kovetskiy/docopt-go/examples"
)

func Example() {
Expand Down
2 changes: 1 addition & 1 deletion examples/config_file/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
"strings"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/counted/counted.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

var usage = `Usage: counted --help
Expand Down
2 changes: 1 addition & 1 deletion examples/counted/counted_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/docopt/docopt-go/examples"
"github.com/kovetskiy/docopt-go/examples"
)

func Example() {
Expand Down
2 changes: 1 addition & 1 deletion examples/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sort"
"strings"

"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

// TestUsage is a helper used to test the output from the examples in this folder.
Expand Down
2 changes: 1 addition & 1 deletion examples/fake-git/branch/git_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/fake-git/checkout/git_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/fake-git/clone/git_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/fake-git/fakegit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
"os"
"os/exec"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/fake-git/push/git_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/fake-git/remote/git_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/naval_fate/naval_fate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/odd_even/odd_even.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/options_shortcut/options_shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/quick/quick.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/type_assert/type_assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/unit_test/unit_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/docopt/docopt-go"
"github.com/kovetskiy/docopt-go"
"reflect"
"testing"
)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/kovetskiy/docopt-go

go 1.21.5
Loading