forked from gobuffalo/buffalo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
34 lines (27 loc) · 766 Bytes
/
action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package destroy
import (
"errors"
"os"
"github.com/markbates/inflect"
"github.com/spf13/cobra"
)
//ActionCmd destroys passed action file
var ActionCmd = &cobra.Command{
Use: "action [name]",
//Example: "resource cars",
Aliases: []string{"a"},
Short: "Destroys action files.",
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := os.Stat(".buffalo.dev.yml"); os.IsNotExist(err) {
return errors.New("destroy needs to run in your buffalo project root")
}
if len(args) == 0 {
return errors.New("you need to provide a valid action file name in order to destroy it")
}
name := args[0]
//Generated actions keep the same name (not plural).
fileName := inflect.Underscore(name)
removeActions(fileName)
return nil
},
}