From f89698667c0b2138445c719101fe7a4d55764738 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Tue, 5 Jan 2016 13:57:01 -0800 Subject: add custom validation example to README --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 93f2574..4a11914 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,18 @@ fmt.Printf("Fetching the following IDs from %s: %q", args.Database, args.IDs) Fetching the following IDs from foo: [1 2 3] ``` +### Custom validation +``` +var args struct { + Foo string + Bar string +} +p := arg.MustParse(&args) +if args.Foo == "" && args.Bar == "" { + p.Fail("you must provide one of --foo and --bar) +} +``` + ### Installation ```shell -- cgit v1.2.3 From 9aad09fe14abea44e32a2dabf4768e1eb31527ea Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Tue, 5 Jan 2016 14:00:29 -0800 Subject: fix example code --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 4a11914..f4c8d11 100644 --- a/README.md +++ b/README.md @@ -109,17 +109,23 @@ Fetching the following IDs from foo: [1 2 3] ``` ### Custom validation -``` +```go var args struct { Foo string Bar string } p := arg.MustParse(&args) if args.Foo == "" && args.Bar == "" { - p.Fail("you must provide one of --foo and --bar) + p.Fail("you must provide one of --foo and --bar") } ``` +```shell +./example +usage: samples [--foo FOO] [--bar BAR] +error: you must provide one of --foo and --bar +``` + ### Installation ```shell -- cgit v1.2.3