Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed May 20, 2018
1 parent 45bfb07 commit e83f736
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ Or just copy & paste what you need. It's public domain.
package main

import (
"flag"
"fmt"
"github.com/sgreben/flagvar"
"flag"
"fmt"
"github.com/sgreben/flagvar"
)

var (
fruit = flagvar.Enum{Choices: []string{"apple","banana"}}
urls flagvar.URLs
settings flagvar.Assignments
fruit = flagvar.Enum{Choices: []string{"apple", "banana"}}
urls flagvar.URLs
settings flagvar.Assignments
)

func main() {
flag.Var(&fruit, "fruit", fmt.Sprintf("set a fruit %v", fruit.Choices))
flag.Var(&urls, "url", "add a URL")
flag.Var(&settings, "set", "set key=value")
flag.Parse()
flag.Var(&fruit, "fruit", fmt.Sprintf("set a fruit (%s)", fruit.Help()))
flag.Var(&urls, "url", "add a URL")
flag.Var(&settings, "set", fmt.Sprintf("specify a setting (%s)", settings.Help()))
flag.Parse()
}
```

Expand All @@ -59,8 +59,17 @@ $ go run main.go -set abc=xyz -url https://github.com
$ go run main.go -set abc=xyz -url ://github.com
invalid value "://github.com" for flag -url: parse ://github.com: missing protocol scheme

$ go run /tmp/main.go -fruit kiwi
$ go run main.go -fruit kiwi
invalid value "kiwi" for flag -fruit: "kiwi" must be one of [apple banana]

$ go run main.go -h
Usage:
-fruit value
set a fruit (one of [apple banana])
-set value
specify a setting (a key/value pair KEY=VALUE)
-url value
add a URL
```

## Conventions
Expand Down

0 comments on commit e83f736

Please sign in to comment.