48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/Jaculabilis/intake/core"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var actionDeleteCmd = &cobra.Command{
|
|
Use: "delete",
|
|
Aliases: []string{"rm"},
|
|
Short: "Delete an action from a source",
|
|
Long: `Delete an action from a source.
|
|
`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
actionDelete(stringArg(cmd, "source"), stringArg(cmd, "action"))
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
actionCmd.AddCommand(actionDeleteCmd)
|
|
|
|
actionDeleteCmd.Flags().StringP("source", "s", "", "Source to add action")
|
|
actionDeleteCmd.MarkFlagRequired("source")
|
|
|
|
actionDeleteCmd.Flags().StringP("action", "a", "", "Action name")
|
|
actionDeleteCmd.MarkFlagRequired("action")
|
|
}
|
|
|
|
func actionDelete(source string, action string) {
|
|
if source == "" {
|
|
log.Fatal("error: --source is empty")
|
|
}
|
|
if action == "" {
|
|
log.Fatal("error: --action is empty")
|
|
}
|
|
|
|
db := openAndMigrateDb()
|
|
|
|
err := core.DeleteAction(db, source, action)
|
|
if err != nil {
|
|
log.Fatalf("error: failed to delete action: %v", err)
|
|
}
|
|
|
|
log.Printf("Deleted action %s from source %s", action, source)
|
|
}
|