@@ -36,32 +36,13 @@ func createCliApp() *cli.App {
3636 cliapp .Version = version
3737
3838 cliapp .Commands = []cli.Command {
39+ createTestCommand (),
3940 createAddCommand (),
40- {
41- Name : "add" ,
42- Usage : "Automatically add a test to your test suite" ,
43- ArgsUsage : "[command]" ,
44- Flags : []cli.Flag {
45- cli.BoolFlag {
46- Name : "stdout" ,
47- Usage : "Output test file to stdout" ,
48- },
49- cli.BoolFlag {
50- Name : "no-file" ,
51- Usage : "Don't create a commander.yaml" ,
52- },
53- cli.StringFlag {
54- Name : "file" ,
55- Usage : "Write to another file, default is commander.yaml" ,
56- },
57- },
58- Action : addCommand ,
59- },
6041 }
6142 return cliapp
6243}
6344
64- func createAddCommand () cli.Command {
45+ func createTestCommand () cli.Command {
6546 return cli.Command {
6647 Name : "test" ,
6748 Usage : "Execute the test suite" ,
@@ -89,35 +70,56 @@ func createAddCommand() cli.Command {
8970 }
9071}
9172
92- func addCommand (c * cli.Context ) error {
93- file := ""
94- var existedContent []byte
73+ func createAddCommand () cli.Command {
74+ return cli.Command {
75+ Name : "add" ,
76+ Usage : "Automatically add a test to your test suite" ,
77+ ArgsUsage : "[command]" ,
78+ Flags : []cli.Flag {
79+ cli.BoolFlag {
80+ Name : "stdout" ,
81+ Usage : "Output test file to stdout" ,
82+ },
83+ cli.BoolFlag {
84+ Name : "no-file" ,
85+ Usage : "Don't create a commander.yaml" ,
86+ },
87+ cli.StringFlag {
88+ Name : "file" ,
89+ Usage : "Write to another file, default is commander.yaml" ,
90+ },
91+ },
92+ Action : func (c * cli.Context ) error {
93+ file := ""
94+ var existedContent []byte
9595
96- if ! c .Bool ("no-file" ) {
97- dir , _ := os .Getwd ()
98- file = path .Join (dir , app .CommanderFile )
99- if c .String ("file" ) != "" {
100- file = c .String ("file" )
101- }
102- existedContent , _ = ioutil .ReadFile (file )
103- }
96+ if ! c .Bool ("no-file" ) {
97+ dir , _ := os .Getwd ()
98+ file = path .Join (dir , app .CommanderFile )
99+ if c .String ("file" ) != "" {
100+ file = c .String ("file" )
101+ }
102+ existedContent , _ = ioutil .ReadFile (file )
103+ }
104104
105- content , err := app .AddCommand (strings .Join (c .Args (), " " ), existedContent )
105+ content , err := app .AddCommand (strings .Join (c .Args (), " " ), existedContent )
106106
107- if err != nil {
108- return err
109- }
107+ if err != nil {
108+ return err
109+ }
110110
111- if c .Bool ("stdout" ) {
112- fmt .Println (string (content ))
113- }
114- if ! c .Bool ("no-file" ) {
115- fmt .Println ("written to" , file )
116- err := ioutil .WriteFile (file , content , 0755 )
117- if err != nil {
118- return err
119- }
120- }
111+ if c .Bool ("stdout" ) {
112+ fmt .Println (string (content ))
113+ }
114+ if ! c .Bool ("no-file" ) {
115+ fmt .Println ("written to" , file )
116+ err := ioutil .WriteFile (file , content , 0755 )
117+ if err != nil {
118+ return err
119+ }
120+ }
121121
122- return nil
122+ return nil
123+ },
124+ }
123125}
0 commit comments