From 23a7f3ca31df657a718f5ccf0d493019dd1f01cb Mon Sep 17 00:00:00 2001 From: C Cirello Date: Tue, 15 Nov 2016 01:34:27 +0100 Subject: [PATCH] fnctl: improve route creation if func.yaml is present (#280) --- fnctl/routes.go | 16 ++++++++++++++-- fnctl/run.go | 1 - 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fnctl/routes.go b/fnctl/routes.go index 8d5cd20af..b3b9c8d13 100644 --- a/fnctl/routes.go +++ b/fnctl/routes.go @@ -172,8 +172,8 @@ func envAsHeader(req *http.Request, selectedEnv []string) { } func (a *routesCmd) create(c *cli.Context) error { - if c.Args().Get(0) == "" || c.Args().Get(1) == "" || c.Args().Get(2) == "" { - return errors.New("error: routes listing takes three arguments: an app name, a route path and an image") + if c.Args().Get(0) == "" || c.Args().Get(1) == "" { + return errors.New("error: routes creation takes three arguments: an app name, a route path and an image") } if err := resetBasePath(&a.Configuration); err != nil { @@ -183,6 +183,18 @@ func (a *routesCmd) create(c *cli.Context) error { appName := c.Args().Get(0) route := c.Args().Get(1) image := c.Args().Get(2) + if image == "" { + ff, err := findFuncfile() + if err != nil { + if _, ok := err.(*NotFoundError); ok { + return errors.New("error: image name is missing or no function file found") + } else { + return err + } + } + image = ff.FullName() + } + body := functions.RouteWrapper{ Route: functions.Route{ AppName: appName, diff --git a/fnctl/run.go b/fnctl/run.go index 3e232a00f..fac6ca328 100644 --- a/fnctl/run.go +++ b/fnctl/run.go @@ -36,7 +36,6 @@ func runflags() []cli.Flag { func (r *runCmd) run(c *cli.Context) error { image := c.Args().First() if image == "" { - // check for a funcfile ff, err := findFuncfile() if err != nil { if _, ok := err.(*NotFoundError); ok {