MCPcopy Create free account
hub / github.com/commander-cli/commander / createAddCommand

Function createAddCommand

cmd/commander/commander.go:110–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108}
109
110func 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}

Callers 1

createCliAppFunction · 0.85

Calls 1

AddCommandFunction · 0.92

Tested by

no test coverage detected