mirror of
https://github.com/spf13/cobra
synced 2024-11-25 07:07:15 +00:00
Merge branch 'master' of github.com:ianwalter/cobra
This commit is contained in:
commit
034973cce1
1 changed files with 11 additions and 6 deletions
|
@ -14,6 +14,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -63,8 +64,7 @@ Example: cobra add server -> resulting in a new cmd/server.go
|
||||||
currentPath += pName + "/"
|
currentPath += pName + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Create command file if it does not already exist.
|
createCmdFile(cmd, currentPath)
|
||||||
createCmdFile(cmd, currentPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// {{ .cmdName | title }}Cmd represents the {{ .cmdName }} command
|
// {{ .cmdName | title }}Cmd represents the {{ .cmdName }} command
|
||||||
{{ .cmdName | title }}Cmd := &cobra.Command{
|
var {{ .cmdName | title }}Cmd = &cobra.Command{
|
||||||
Use: "{{ .cmdName }}",
|
Use: "{{ .cmdName }}",
|
||||||
Short: "A brief description of your command",
|
Short: "A brief description of your command",
|
||||||
Long: ` + "`" + `A longer description that spans multiple lines and likely contains examples
|
Long: ` + "`" + `A longer description that spans multiple lines and likely contains examples
|
||||||
|
@ -147,8 +147,13 @@ func init() {
|
||||||
|
|
||||||
file := filepath.Join(ProjectPath(), guessCmdDir(), cmdPath, cmdName+".go")
|
file := filepath.Join(ProjectPath(), guessCmdDir(), cmdPath, cmdName+".go")
|
||||||
|
|
||||||
if err := writeTemplateToFile(file, template, data); err != nil {
|
// Check if the file exists before trying to create it.
|
||||||
er(err)
|
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||||
|
if err := writeTemplateToFile(file, template, data); err != nil {
|
||||||
|
er(err)
|
||||||
|
}
|
||||||
|
fmt.Println(cmdName, "created at", file)
|
||||||
|
} else {
|
||||||
|
fmt.Println(cmdName, "already exists at", file)
|
||||||
}
|
}
|
||||||
fmt.Println(cmdName, "created at", file)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue