2022-05-12 02:11:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2022-07-10 21:55:47 +00:00
|
|
|
"git.meatballhat.com/x/argh"
|
2022-05-29 23:16:13 +00:00
|
|
|
"github.com/davecgh/go-spew/spew"
|
2022-05-12 02:11:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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-06 23:06:50 +00:00
|
|
|
pCfg := argh.NewParserConfig()
|
2022-06-07 13:47:12 +00:00
|
|
|
pCfg.Prog = &argh.CommandConfig{
|
2022-06-06 23:06:50 +00:00
|
|
|
NValue: argh.OneOrMoreValue,
|
2022-07-10 21:36:13 +00:00
|
|
|
ValueNames: []string{"val"},
|
2022-06-06 23:06:50 +00:00
|
|
|
Flags: &argh.Flags{
|
|
|
|
Automatic: true,
|
2022-06-04 21:38:24 +00:00
|
|
|
},
|
2022-06-06 23:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pt, err := argh.ParseArgs(os.Args, pCfg)
|
2022-05-12 02:11:05 +00:00
|
|
|
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-12 02:11:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-29 23:16:13 +00:00
|
|
|
spew.Dump(ast)
|
2022-05-12 02:11:05 +00:00
|
|
|
}
|