check if command exists before attempting to create

This commit is contained in:
kodejuice 2021-02-27 06:54:38 +01:00
parent eb3b6397b1
commit 13e5bcf908

View file

@ -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
}