()
| 108 | } |
| 109 | |
| 110 | func createAddCommand() cli.Command { |
| 111 | return cli.Command{ |
| 112 | Name: "add", |
| 113 | Usage: "Automatically add a test to your test suite", |
| 114 | ArgsUsage: "[command]", |
| 115 | Flags: []cli.Flag{ |
| 116 | cli.BoolFlag{ |
| 117 | Name: "stdout", |
| 118 | Usage: "Output test file to stdout", |
| 119 | }, |
| 120 | cli.BoolFlag{ |
| 121 | Name: "no-file", |
| 122 | Usage: "Don't create a commander.yaml", |
| 123 | }, |
| 124 | cli.StringFlag{ |
| 125 | Name: "file", |
| 126 | Usage: "Write to another file, default is commander.yaml", |
| 127 | }, |
| 128 | }, |
| 129 | Action: func(c *cli.Context) error { |
| 130 | file := "" |
| 131 | var existedContent []byte |
| 132 | |
| 133 | if !c.Bool("no-file") { |
| 134 | dir, _ := os.Getwd() |
| 135 | file = path.Join(dir, app.CommanderFile) |
| 136 | if c.String("file") != "" { |
| 137 | file = c.String("file") |
| 138 | } |
| 139 | existedContent, _ = ioutil.ReadFile(file) |
| 140 | } |
| 141 | |
| 142 | content, err := app.AddCommand(strings.Join(c.Args(), " "), existedContent) |
| 143 | |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } |
| 147 | |
| 148 | if c.Bool("stdout") { |
| 149 | fmt.Println(string(content)) |
| 150 | } |
| 151 | if !c.Bool("no-file") { |
| 152 | fmt.Println("written to", file) |
| 153 | err := ioutil.WriteFile(file, content, 0755) |
| 154 | if err != nil { |
| 155 | return err |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return nil |
| 160 | }, |
| 161 | } |
| 162 | } |
no test coverage detected