Skip to content

Commit

Permalink
Make simple example slightly less simple
Browse files Browse the repository at this point in the history
  • Loading branch information
meatballhat committed Jun 14, 2023
1 parent f5881bd commit b9823d7
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions example_test.go
Expand Up @@ -14,12 +14,26 @@ func ExampleParserConfig_simple() {
NValue: argh.OneOrMoreValue,
ValueNames: []string{"val"},
Flags: &argh.Flags{
Automatic: true,
Map: map[string]argh.FlagConfig{
"a": {
NValue: 2,
On: func(cf argh.CommandFlag) {
fmt.Printf("prog -a Name: %[1]q\n", cf.Name)
fmt.Printf("prog -a Values: %[1]q\n", cf.Values)
fmt.Printf("prog -a len(Nodes): %[1]v\n", len(cf.Nodes))
},
},
},
},
On: func(cf argh.CommandFlag) {
fmt.Printf("prog Name: %[1]q\n", cf.Name)
fmt.Printf("prog Values: %[1]q\n", cf.Values)
fmt.Printf("prog len(Nodes): %[1]v\n", len(cf.Nodes))
},
}

// simulate command line args
os.Args = []string{"hello", "there"}
os.Args = []string{"hello", "-a=from", "the", "ether"}

pt, err := argh.ParseArgs(os.Args, pCfg)
if err != nil {
Expand All @@ -32,8 +46,11 @@ func ExampleParserConfig_simple() {
log.Fatal("no parse tree?")
}

fmt.Printf("parsed!\n")

// Output:
// parsed!
// prog -a Name: "a"
// prog -a Values: map["0":"from" "1":"the"]
// prog -a len(Nodes): 4
// prog Name: "hello"
// prog Values: map["val":"ether"]
// prog len(Nodes): 4
}

0 comments on commit b9823d7

Please sign in to comment.