Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed May 21, 2022
1 parent 44eb7a3 commit 0df126a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,20 @@ go get github.com/cristalhq/flagx
## Example

```go
fset := flagx.NewFlagSet("testing")
d := fset.Duration("timeout", "t", 10*time.Second, "just a timeout")
args := []string{"-t", "20s"}

err := fset.Parse([]string{"-t", "20s"})
var d time.Duration
fset := flagx.NewFlagSet("testing", os.Stderr)
fset.Duration(&d, "timeout", "t", 10*time.Second, "just a timeout")

err := fset.Parse(args)
if err != nil {
panic(err)
}

fmt.Println(d)

// Output: 20s
```

Also see examples: [examples_test.go](https://github.com/cristalhq/flagx/blob/main/example_test.go).
Expand Down
10 changes: 5 additions & 5 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
)

func ExampleFlagSet() {
args := []string{"-t", "20s"}

var d time.Duration
fset := flagx.NewFlagSet("testing", os.Stderr)
fset.Duration(&d, "timeout", "t", 10*time.Second, "just a timeout")

err := fset.Parse([]string{"-t", "20s"})
err := fset.Parse(args)
if err != nil {
panic(err)
}

if d != 20*time.Second {
panic(fmt.Sprintf("got %v want %v", d, 20*time.Second))
}
fmt.Println(d)

// Output:
// Output: 20s
}

func ExampleTextVar() {
Expand Down

0 comments on commit 0df126a

Please sign in to comment.