udpate readme

This commit is contained in:
Alex Flint 2015-10-31 18:49:20 -07:00
parent 04e96c0c6b
commit 6582088596
1 changed files with 9 additions and 11 deletions

View File

@ -1,6 +1,6 @@
# Argument parsing for Go # Argument parsing for Go
```golang ```go
import "github.com/alexflint/go-arg" import "github.com/alexflint/go-arg"
var args struct { var args struct {
@ -8,19 +8,17 @@ var args struct {
Bar bool Bar bool
} }
arg.MustParse(&args) arg.MustParse(&args)
fmt.Println(args.Foo) fmt.Println(args.Foo, args.Bar)
fmt.Println(args.Bar)
``` ```
```bash ```shell
$ ./example --foo=hello --bar $ ./example --foo=hello --bar
hello hello True
True
``` ```
### Default values ### Default values
```golang ```go
var args struct { var args struct {
Foo string Foo string
Bar bool Bar bool
@ -31,7 +29,7 @@ arg.MustParse(&args)
### Marking options as required ### Marking options as required
```golang ```go
var args struct { var args struct {
Foo string `arg:"required"` Foo string `arg:"required"`
Bar bool Bar bool
@ -41,7 +39,7 @@ arg.MustParse(&args)
### Positional argument ### Positional argument
```golang ```go
var args struct { var args struct {
Input string `arg:"positional"` Input string `arg:"positional"`
Output []string `arg:"positional"` Output []string `arg:"positional"`
@ -59,7 +57,7 @@ Output: [x.out y.out z.out]
``` ```
### Usage strings ### Usage strings
```bash ```shell
$ ./example -h $ ./example -h
usage: [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--help] INPUT [OUTPUT [OUTPUT ...]] usage: [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--help] INPUT [OUTPUT [OUTPUT ...]]
@ -85,7 +83,7 @@ arg.MustParse(&args)
fmt.Printf("Fetching the following IDs from %s: %q", args.Database, args.IDs) fmt.Printf("Fetching the following IDs from %s: %q", args.Database, args.IDs)
``` ```
```bash ```shell
./example -database foo -ids 1 2 3 ./example -database foo -ids 1 2 3
Fetching the following IDs from foo: [1 2 3] Fetching the following IDs from foo: [1 2 3]
``` ```