udpate readme

This commit is contained in:
Alex Flint 2015-10-31 18:48:38 -07:00
parent 22c73471e6
commit 04e96c0c6b
4 changed files with 15 additions and 13 deletions

View File

@ -1,6 +1,8 @@
Argument parsing for Go.
# Argument parsing for Go
```golang
import "github.com/alexflint/go-arg"
var args struct {
Foo string
Bar bool
@ -16,7 +18,7 @@ hello
True
```
Setting defaults values:
### Default values
```golang
var args struct {
@ -27,7 +29,7 @@ args.Foo = "default value"
arg.MustParse(&args)
```
Marking options as required
### Marking options as required
```golang
var args struct {
@ -37,7 +39,7 @@ var args struct {
arg.MustParse(&args)
```
Positional argument:
### Positional argument
```golang
var args struct {
@ -56,7 +58,7 @@ Input: src.txt
Output: [x.out y.out z.out]
```
Usage strings:
### Usage strings
```bash
$ ./example -h
usage: [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] [--help] INPUT [OUTPUT [OUTPUT ...]]
@ -73,7 +75,7 @@ options:
--help, -h print this help message
```
Options with multiple values:
### Options with multiple values
```
var args struct {
Database string

View File

@ -4,11 +4,11 @@ import "github.com/alexflint/go-arg"
func main() {
var args struct {
Input string `arg:"positional"`
Output string `arg:"positional"`
Foo string `arg:"help:this argument is foo"`
VeryLongArgument int `arg:"help:this argument is very long"`
Bar float64 `arg:"-b"`
Input string `arg:"positional"`
Output []string `arg:"positional"`
Verbose bool `arg:"-v,help:verbosity level"`
Dataset string `arg:"help:dataset to use"`
Optimize int `arg:"-O,help:optimization level"`
}
arg.MustParse(&args)
}

View File

@ -38,7 +38,7 @@ func Parse(dest ...interface{}) error {
func ParseFrom(args []string, dest ...interface{}) error {
// Add the help option if one is not already defined
var internal struct {
Help bool `arg:"-h"`
Help bool `arg:"-h,help:print this help message"`
}
// Parse the spec

View File

@ -72,7 +72,7 @@ func writeUsage(w io.Writer, specs []*spec) {
for _, spec := range positionals {
up := strings.ToUpper(spec.long)
if spec.multiple {
fmt.Fprintf(w, "[%s [%s ...]]", up)
fmt.Fprintf(w, "[%s [%s ...]]", up, up)
} else {
fmt.Fprint(w, up)
}