@@ -19,6 +19,9 @@ import (
1919
2020// Template for main starts here
2121
22+ // // for `go generate -x`
23+ // //go:generate sh jsonfiddle_cliGen.sh
24+
2225//////////////////////////////////////////////////////////////////////////
2326// Constant and data type/structure definitions
2427
@@ -28,23 +31,23 @@ import (
2831// var (
2932// progname = "jsonfiddle"
3033// version = "0.1.0"
31- // date = "2025-01-15 "
34+ // date = "2025-11-18 "
3235
33- // // opts store all the configurable options
34- // opts optsT
36+ // // Opts store all the configurable options
37+ // Opts OptsT
3538// )
3639//
37- // var gfParser = flags.NewParser(&opts , flags.Default)
40+ // var gfParser = flags.NewParser(&Opts , flags.Default)
3841
3942////////////////////////////////////////////////////////////////////////////
4043// Function definitions
4144
4245//==========================================================================
4346// Function main
4447// func main() {
45- // opts .Version = showVersion
46- // opts .Verbflg = func() {
47- // opts .Verbose++
48+ // Opts .Version = showVersion
49+ // Opts .Verbflg = func() {
50+ // Opts .Verbose++
4851// }
4952//
5053// if _, err := gfParser.Parse(); err != nil {
@@ -75,8 +78,8 @@ import (
7578
7679// Template for type define starts here
7780
78- // The optsT type defines all the configurable options from cli.
79- type optsT struct {
81+ // The OptsT type defines all the configurable options from cli.
82+ type OptsT struct {
8083 Compact bool `short:"c" long:"compact" description:"Compact JSON data, remove all whitespaces"`
8184 Prefix string `long:"prefix" description:"prefix for json string output"`
8285 Indent string `short:"d" long:"indent" description:"indent for json string output" default:" "`
@@ -124,15 +127,16 @@ type optsT struct {
124127// func init() {
125128// gfParser.AddCommand("esc",
126129// "Escape json string",
127- // "",
130+ // `
131+ // `,
128132// &escCommand)
129133// }
130134//
131135// func (x *EscCommand) Execute(args []string) error {
132136// fmt.Fprintf(os.Stderr, "Escape json string\n")
133137// // fmt.Fprintf(os.Stderr, "Copyright (C) 2017-2025, Tong Sun\n\n")
134- // clis.Setup("jsonfiddle::esc", opts .Verbose)
135- // clis.Verbose(1, "Doing Esc, with %+v, %+v", opts , args)
138+ // clis.Setup("jsonfiddle::esc", Opts .Verbose)
139+ // clis.Verbose(1, "Doing Esc, with %+v, %+v", Opts , args)
136140// // fmt.Println(x.Filei, x.Fileo)
137141// return x.Exec(args)
138142// }
@@ -172,6 +176,7 @@ type optsT struct {
172176// type FmtCommand struct {
173177// Filei string `short:"i" long:"input" description:"the source to get json string from (mandatory)" required:"true"`
174178// Fileo string `short:"o" long:"output" description:"the output, default to stdout" default:"-"`
179+ // Concise bool `short:"s" long:"concise" description:"Compact the top level array into concise array style"`
175180// Unescape bool `short:"u" long:"unescape" description:"Unescape unicode of form \u003c to their literal characters"`
176181// }
177182
@@ -184,16 +189,17 @@ type optsT struct {
184189// func init() {
185190// gfParser.AddCommand("fmt",
186191// "Format json string",
187- // "",
192+ // `
193+ // `,
188194// &fmtCommand)
189195// }
190196//
191197// func (x *FmtCommand) Execute(args []string) error {
192198// fmt.Fprintf(os.Stderr, "Format json string\n")
193199// // fmt.Fprintf(os.Stderr, "Copyright (C) 2017-2025, Tong Sun\n\n")
194- // clis.Setup("jsonfiddle::fmt", opts .Verbose)
195- // clis.Verbose(1, "Doing Fmt, with %+v, %+v", opts , args)
196- // // fmt.Println(x.Filei, x.Fileo, x.Unescape)
200+ // clis.Setup("jsonfiddle::fmt", Opts .Verbose)
201+ // clis.Verbose(1, "Doing Fmt, with %+v, %+v", Opts , args)
202+ // // fmt.Println(x.Filei, x.Fileo, x.Concise, x. Unescape)
197203// return x.Exec(args)
198204// }
199205//
@@ -243,15 +249,16 @@ type optsT struct {
243249// func init() {
244250// gfParser.AddCommand("sort",
245251// "Sort json fields recursively",
246- // "",
252+ // `
253+ // `,
247254// &sortCommand)
248255// }
249256//
250257// func (x *SortCommand) Execute(args []string) error {
251258// fmt.Fprintf(os.Stderr, "Sort json fields recursively\n")
252259// // fmt.Fprintf(os.Stderr, "Copyright (C) 2017-2025, Tong Sun\n\n")
253- // clis.Setup("jsonfiddle::sort", opts .Verbose)
254- // clis.Verbose(1, "Doing Sort, with %+v, %+v", opts , args)
260+ // clis.Setup("jsonfiddle::sort", Opts .Verbose)
261+ // clis.Verbose(1, "Doing Sort, with %+v, %+v", Opts , args)
255262// // fmt.Println(x.Filei, x.Fileo)
256263// return x.Exec(args)
257264// }
@@ -306,15 +313,16 @@ type optsT struct {
306313// func init() {
307314// gfParser.AddCommand("j2s",
308315// "JSON to struct",
309- // "JSON convert to Go struct",
316+ // `JSON convert to Go struct
317+ // `,
310318// &j2sCommand)
311319// }
312320//
313321// func (x *J2sCommand) Execute(args []string) error {
314322// fmt.Fprintf(os.Stderr, "JSON to struct\n")
315323// // fmt.Fprintf(os.Stderr, "Copyright (C) 2017-2025, Tong Sun\n\n")
316- // clis.Setup("jsonfiddle::j2s", opts .Verbose)
317- // clis.Verbose(1, "Doing J2s, with %+v, %+v", opts , args)
324+ // clis.Setup("jsonfiddle::j2s", Opts .Verbose)
325+ // clis.Verbose(1, "Doing J2s, with %+v, %+v", Opts , args)
318326// // fmt.Println(x.FmtType, x.Filei, x.Fileo, x.Name, x.Pkg, x.SubStruct)
319327// return x.Exec(args)
320328// }
@@ -365,15 +373,16 @@ type optsT struct {
365373// func init() {
366374// gfParser.AddCommand("x2j",
367375// "XML to JSON",
368- // "",
376+ // `
377+ // `,
369378// &x2jCommand)
370379// }
371380//
372381// func (x *X2jCommand) Execute(args []string) error {
373382// fmt.Fprintf(os.Stderr, "XML to JSON\n")
374383// // fmt.Fprintf(os.Stderr, "Copyright (C) 2017-2025, Tong Sun\n\n")
375- // clis.Setup("jsonfiddle::x2j", opts .Verbose)
376- // clis.Verbose(1, "Doing X2j, with %+v, %+v", opts , args)
384+ // clis.Setup("jsonfiddle::x2j", Opts .Verbose)
385+ // clis.Verbose(1, "Doing X2j, with %+v, %+v", Opts , args)
377386// // fmt.Println(x.Filei, x.Fileo)
378387// return x.Exec(args)
379388// }
0 commit comments