feat main: Add 'delete' command

This commit is contained in:
Vincent Ambo 2017-02-08 18:06:47 +01:00
parent dd2fdd63e5
commit c046e5acff

22
main.go
View file

@ -26,6 +26,7 @@ func main() {
templateCommand(), templateCommand(),
applyCommand(), applyCommand(),
replaceCommand(), replaceCommand(),
deleteCommand(),
} }
app.Run(os.Args) app.Run(os.Args)
@ -109,6 +110,27 @@ func replaceCommand() cli.Command {
} }
} }
func deleteCommand() cli.Command {
return cli.Command{
Name: "delete",
Usage: "Interpolate templates and run 'kubectl delete'",
Flags: commonFlags(),
Action: func(c *cli.Context) error {
include := c.StringSlice("include")
exclude := c.StringSlice("exclude")
ctx, err := loadContext(c)
resources, err := templater.LoadAndPrepareTemplates(&include, &exclude, ctx)
if err != nil {
return err
}
args := []string{"delete", "-f", "-"}
return runKubectlWithResources(ctx, &args, &resources)
},
}
}
func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resources *[]string) error { func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resources *[]string) error {
args := append(*kubectlArgs, fmt.Sprintf("--context=%s", c.Name)) args := append(*kubectlArgs, fmt.Sprintf("--context=%s", c.Name))