summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md14
-rw-r--r--example/example.go10
-rw-r--r--parse.go2
-rw-r--r--usage.go2
4 files changed, 15 insertions, 13 deletions
diff --git a/README.md b/README.md
index d45a31f..f3db6c9 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/example/example.go b/example/example.go
index 20efeec..1b1c7e0 100644
--- a/example/example.go
+++ b/example/example.go
@@ -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)
}
diff --git a/parse.go b/parse.go
index d9382c9..6e7f4bd 100644
--- a/parse.go
+++ b/parse.go
@@ -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
diff --git a/usage.go b/usage.go
index 06a3ebd..5155d82 100644
--- a/usage.go
+++ b/usage.go
@@ -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)
}