argh/cmd/argh-example/main.go

47 lines
682 B
Go
Raw Normal View History

package main
import (
"encoding/json"
"fmt"
"log"
"os"
"git.meatballhat.com/x/box-o-sand/argh"
2022-05-29 23:16:13 +00:00
"github.com/davecgh/go-spew/spew"
)
func main() {
2022-05-29 23:16:13 +00:00
asJSON := os.Getenv("ARGH_OUTPUT_JSON") == "enabled"
2022-05-14 00:58:55 +00:00
log.SetFlags(0)
2022-06-04 21:38:24 +00:00
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)
}
2022-05-29 23:16:13 +00:00
ast := argh.NewQuerier(pt.Nodes).AST()
if asJSON {
b, err := json.MarshalIndent(ast, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
return
}
2022-05-29 23:16:13 +00:00
spew.Dump(ast)
}