Making more messes with parser config
This commit is contained in:
46
argh/cmd/argh-example/main.go
Normal file
46
argh/cmd/argh-example/main.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.meatballhat.com/x/box-o-sand/argh"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func main() {
|
||||
asJSON := os.Getenv("ARGH_OUTPUT_JSON") == "enabled"
|
||||
|
||||
log.SetFlags(0)
|
||||
|
||||
pt, err := argh.ParseArgs(os.Args, argh.NewParserConfig(
|
||||
&argh.CommandConfig{
|
||||
NValue: argh.OneOrMoreValue,
|
||||
ValueNames: []string{"topping"},
|
||||
Flags: &argh.Flags{
|
||||
Automatic: true,
|
||||
},
|
||||
},
|
||||
nil,
|
||||
))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ast := argh.NewQuerier(pt.Nodes).AST()
|
||||
|
||||
if asJSON {
|
||||
b, err := json.MarshalIndent(ast, "", " ")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(string(b))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
spew.Dump(ast)
|
||||
}
|
Reference in New Issue
Block a user