Skip to content

Commit 71b3f56

Browse files
committed
- [+] add cmd esc wireframe, Escape json string
1 parent b792669 commit 71b3f56

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

cmdEsc.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
////////////////////////////////////////////////////////////////////////////
2+
// Program: jsonfiddle
3+
// Purpose: JSON Fiddling
4+
// Authors: Tong Sun (c) 2017, All rights reserved
5+
////////////////////////////////////////////////////////////////////////////
6+
7+
package main
8+
9+
import (
10+
"fmt"
11+
12+
"github.com/mkideal/cli"
13+
)
14+
15+
func escCLI(ctx *cli.Context) error {
16+
rootArgv = ctx.RootArgv().(*rootT)
17+
argv := ctx.Argv().(*escT)
18+
fmt.Printf("[esc]:\n %+v\n %+v\n %v\n", rootArgv, argv, ctx.Args())
19+
return nil
20+
}

jsonfiddle.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ Options:
3838

3939
Command:
4040

41+
- Name: esc
42+
Desc: "Escape json string so as to embed it as content of json string"
43+
NumOption: cli.AtLeast(1)
44+
45+
Options:
46+
- Name: Filei
47+
Type: '*clix.Reader'
48+
Flag: '*i,input'
49+
Usage: the source to get json string from (mandatory)
50+
51+
- Name: Fileo
52+
Type: '*clix.Writer'
53+
Flag: o,output
54+
Usage: 'the output (default: stdout)'
55+
4156
- Name: fmt
4257
Desc: "Format json string"
4358
#NumArg: cli.AtLeast(1)

jsonfiddleCLIDef.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var root = &cli.Command{
4343
// var (
4444
// progname = "jsonfiddle"
4545
// version = "0.1.0"
46-
// date = "2017-08-12"
46+
// date = "2017-08-14"
4747
// )
4848

4949
// var rootArgv *rootT
@@ -57,6 +57,7 @@ var root = &cli.Command{
5757
// //NOTE: You can set any writer implements io.Writer
5858
// // default writer is os.Stdout
5959
// if err := cli.Root(root,
60+
// cli.Tree(escDef),
6061
// cli.Tree(fmtDef),
6162
// cli.Tree(sortDef),
6263
// cli.Tree(j2sDef)).Run(os.Args[1:]); err != nil {
@@ -79,6 +80,31 @@ var root = &cli.Command{
7980

8081
// Template for CLI handling starts here
8182

83+
////////////////////////////////////////////////////////////////////////////
84+
// esc
85+
86+
// func escCLI(ctx *cli.Context) error {
87+
// rootArgv = ctx.RootArgv().(*rootT)
88+
// argv := ctx.Argv().(*escT)
89+
// fmt.Printf("[esc]:\n %+v\n %+v\n %v\n", rootArgv, argv, ctx.Args())
90+
// return nil
91+
// }
92+
93+
type escT struct {
94+
Filei *clix.Reader `cli:"*i,input" usage:"the source to get json string from (mandatory)"`
95+
Fileo *clix.Writer `cli:"o,output" usage:"the output (default: stdout)"`
96+
}
97+
98+
var escDef = &cli.Command{
99+
Name: "esc",
100+
Desc: "Escape json string so as to embed it as content of json string",
101+
102+
Argv: func() interface{} { return new(escT) },
103+
Fn: escCLI,
104+
105+
NumOption: cli.AtLeast(1),
106+
}
107+
82108
////////////////////////////////////////////////////////////////////////////
83109
// fmt
84110

jsonfiddleMain.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ type OptsT struct {
3333
var (
3434
progname = "jsonfiddle"
3535
// version tracks the release version.
36-
version = "v0.2.0"
37-
date = "2017-07-13"
36+
version = "v0.3.0"
37+
date = "2017-08-16"
3838
)
3939

4040
var (
@@ -51,6 +51,7 @@ func main() {
5151
//NOTE: You can set any writer implements io.Writer
5252
// default writer is os.Stdout
5353
if err := cli.Root(root,
54+
cli.Tree(escDef),
5455
cli.Tree(fmtDef),
5556
cli.Tree(sortDef),
5657
cli.Tree(j2sDef)).Run(os.Args[1:]); err != nil {

0 commit comments

Comments
 (0)