@@ -35,14 +35,14 @@ func main() {
3535 "Let's try 'cat {.json|.yaml|.toml} | xtree output'." ,
3636 Flags : []cli.Flag {
3737 & cli.BoolFlag {
38- Name : "show -index" ,
39- Aliases : []string {"index " , "i " },
40- Usage : "set this option when you want to display array element numbers ( indices) ." ,
38+ Name : "omit -index" ,
39+ Aliases : []string {"omit " , "o " },
40+ Usage : "set this option when you do not want to display array indices." ,
4141 },
4242 & cli.BoolFlag {
4343 Name : "allow-duplicate" ,
4444 Aliases : []string {"a" },
45- Usage : "set this option when you want to allow duplicate node names at the same level" ,
45+ Usage : "set this option when you want to allow duplicate node names at the same level. " ,
4646 },
4747 },
4848 Before : notExistArgs ,
@@ -71,12 +71,12 @@ func actionOutput(ctx context.Context, c *cli.Command) error {
7171 if c .Bool ("allow-duplicate" ) {
7272 root = gtree .NewRoot ("." , gtree .WithDuplicationAllowed ())
7373 }
74- showIndex := c .Bool ("show -index" )
74+ omitIndex := c .Bool ("omit -index" )
7575
76- return output (os .Stdout , os .Stdin , root , showIndex )
76+ return output (os .Stdout , os .Stdin , root , omitIndex )
7777}
7878
79- func output (w io.Writer , r io.Reader , root * gtree.Node , showIndex bool ) error {
79+ func output (w io.Writer , r io.Reader , root * gtree.Node , omitIndex bool ) error {
8080 input , err := io .ReadAll (r )
8181 if err != nil {
8282 return err
@@ -85,7 +85,7 @@ func output(w io.Writer, r io.Reader, root *gtree.Node, showIndex bool) error {
8585 if err != nil {
8686 return err
8787 }
88- walk (root , "" , data , showIndex )
88+ walk (root , "" , data , omitIndex )
8989
9090 return gtree .OutputFromRoot (w , root )
9191}
@@ -106,7 +106,7 @@ func parseData(data []byte) (any, error) {
106106 return nil , errors .New ("data is in an unsupported format or is invalid" )
107107}
108108
109- func walk (parent * gtree.Node , key string , value any , showIndex bool ) {
109+ func walk (parent * gtree.Node , key string , value any , omitIndex bool ) {
110110 switch v := value .(type ) {
111111 case map [string ]any :
112112 node := parent
@@ -121,7 +121,7 @@ func walk(parent *gtree.Node, key string, value any, showIndex bool) {
121121 sort .Strings (keys )
122122
123123 for _ , k := range keys {
124- walk (node , k , v [k ], showIndex )
124+ walk (node , k , v [k ], omitIndex )
125125 }
126126
127127 case map [any ]any :
@@ -130,7 +130,7 @@ func walk(parent *gtree.Node, key string, value any, showIndex bool) {
130130 node = parent .Add (key )
131131 }
132132 for k , val := range v {
133- walk (node , fmt .Sprintf ("%v" , k ), val , showIndex )
133+ walk (node , fmt .Sprintf ("%v" , k ), val , omitIndex )
134134 }
135135
136136 case []any :
@@ -140,11 +140,11 @@ func walk(parent *gtree.Node, key string, value any, showIndex bool) {
140140 }
141141
142142 for i , item := range v {
143- if showIndex {
144- indexNode := node .Add (fmt .Sprintf ("[%d]" , i ))
145- walk (indexNode , "" , item , showIndex )
143+ if omitIndex {
144+ walk (node , "" , item , omitIndex )
146145 } else {
147- walk (node , "" , item , showIndex )
146+ indexNode := node .Add (fmt .Sprintf ("[%d]" , i ))
147+ walk (indexNode , "" , item , omitIndex )
148148 }
149149 }
150150
0 commit comments