mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
check if command exists before attempting to create
This commit is contained in:
parent
eb3b6397b1
commit
13e5bcf908
1 changed files with 8 additions and 1 deletions
|
@ -83,7 +83,14 @@ func (p *Project) createLicenseFile() error {
|
|||
}
|
||||
|
||||
func (c *Command) Create() error {
|
||||
cmdFile, err := os.Create(fmt.Sprintf("%s/cmd/%s.go", c.AbsolutePath, c.CmdName))
|
||||
fileName := fmt.Sprintf("%s/cmd/%s.go", c.AbsolutePath, c.CmdName)
|
||||
|
||||
// check if Command exists
|
||||
if _, err := os.Stat(fileName); err == nil {
|
||||
return fmt.Errorf("command '%s' already exists", c.CmdName)
|
||||
}
|
||||
|
||||
cmdFile, err := os.Create(fileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue