Skip to content

Commit

Permalink
doc: added example of InvalidOption (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk authored Oct 30, 2023
1 parent 90dc9f9 commit 832f5bc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ And help text can be generated as follows:
// (stdout)
// This is the usage of this command.
//
// OPTIONS
// OPTIONS:
// --foo The description of foo option.
// ...
//
// SUB COMMANDS
// SUB COMMANDS:
// list The description of list sub-command.
// --bar The description of bar option.
// ...
Expand Down
28 changes: 28 additions & 0 deletions example_invalid-option_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cliargs_test

import (
"fmt"
"os"

"github.com/sttk/cliargs"
)

func ExampleInvalidOption() {
optCfgs := []cliargs.OptCfg{
cliargs.OptCfg{
Name: "foo",
Default: []string{"123"},
HasArg: false,
},
}

_, e := cliargs.ParseWith(os.Args, optCfgs)
ee := e.(cliargs.InvalidOption)

fmt.Printf("error type: %T\n", ee)
fmt.Printf("option: %s\n", ee.GetOpt())

// Output:
// error type: cliargs.ConfigHasDefaultButHasNoArg
// option: foo
}

0 comments on commit 832f5bc

Please sign in to comment.