fix main: Don't panic if file is unspecified

Instead of printing a spooky stacktrace when the user forgets to specify
the `-f` argument, return an error a lot more gracefully.
This commit is contained in:
Vincent Ambo 2017-04-04 13:47:53 +02:00
parent 3b0f41e71d
commit 4eadb58841

20
main.go
View file

@ -75,8 +75,11 @@ func applyCommand() cli.Command {
include := c.StringSlice("include") include := c.StringSlice("include")
exclude := c.StringSlice("exclude") exclude := c.StringSlice("exclude")
ctx, err := loadContext(c) ctx, err := loadContext(c)
resources, err := templater.LoadAndPrepareTemplates(&include, &exclude, ctx) if err != nil {
return err
}
resources, err := templater.LoadAndPrepareTemplates(&include, &exclude, ctx)
if err != nil { if err != nil {
return err return err
} }
@ -102,8 +105,11 @@ func replaceCommand() cli.Command {
include := c.StringSlice("include") include := c.StringSlice("include")
exclude := c.StringSlice("exclude") exclude := c.StringSlice("exclude")
ctx, err := loadContext(c) ctx, err := loadContext(c)
resources, err := templater.LoadAndPrepareTemplates(&include, &exclude, ctx) if err != nil {
return err
}
resources, err := templater.LoadAndPrepareTemplates(&include, &exclude, ctx)
if err != nil { if err != nil {
return err return err
} }
@ -122,9 +128,13 @@ func deleteCommand() cli.Command {
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
include := c.StringSlice("include") include := c.StringSlice("include")
exclude := c.StringSlice("exclude") exclude := c.StringSlice("exclude")
ctx, err := loadContext(c)
resources, err := templater.LoadAndPrepareTemplates(&include, &exclude, ctx)
ctx, err := loadContext(c)
if err != nil {
return err
}
resources, err := templater.LoadAndPrepareTemplates(&include, &exclude, ctx)
if err != nil { if err != nil {
return err return err
} }
@ -186,7 +196,7 @@ func loadContext(c *cli.Context) (*context.Context, error) {
return nil, meep.New( return nil, meep.New(
&meep.ErrInvalidParam{ &meep.ErrInvalidParam{
Param: "file", Param: "file",
Reason: "Cluster config file must be specified", Reason: "Cluster config file must be specified (-f)",
}, },
) )
} }