fnctl: change from host/scheme flag to endpoint flag (#231)

* fnctl: change from host/schem flag to endpoint flag

* keep same format
This commit is contained in:
Pedro Nasser
2016-11-07 16:48:16 -02:00
committed by C Cirello
parent 946cd85119
commit 1276de223a
4 changed files with 31 additions and 21 deletions

View File

@@ -32,7 +32,9 @@ func apps() cli.Command {
} }
func (a *appsCmd) list(c *cli.Context) error { func (a *appsCmd) list(c *cli.Context) error {
resetBasePath(&a.Configuration) if err := resetBasePath(&a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
wrapper, _, err := a.AppsGet() wrapper, _, err := a.AppsGet()
if err != nil { if err != nil {
@@ -56,7 +58,9 @@ func (a *appsCmd) create(c *cli.Context) error {
return errors.New("error: app creating takes one argument, an app name") return errors.New("error: app creating takes one argument, an app name")
} }
resetBasePath(&a.Configuration) if err := resetBasePath(&a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
appName := c.Args().Get(0) appName := c.Args().Get(0)
body := functions.AppWrapper{App: functions.App{Name: appName}} body := functions.AppWrapper{App: functions.App{Name: appName}}

View File

@@ -30,29 +30,25 @@ func main() {
app.Run(os.Args) app.Run(os.Args)
} }
func resetBasePath(c *functions.Configuration) { func resetBasePath(c *functions.Configuration) error {
var u url.URL u, err := url.Parse(c.Host)
u.Scheme = c.Scheme if err != nil {
u.Host = c.Host return err
}
u.Path = "/v1" u.Path = "/v1"
c.BasePath = u.String() c.BasePath = u.String()
return nil
} }
func confFlags(c *functions.Configuration) []cli.Flag { func confFlags(c *functions.Configuration) []cli.Flag {
return []cli.Flag{ return []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "host", Name: "endpoint",
Usage: "raw host path to functions api, e.g. functions.iron.io", Usage: "url to functions api endpoint e.g. http://functions.iron.io",
Destination: &c.Host, Destination: &c.Host,
EnvVar: "HOST", EnvVar: "HOST",
Value: "localhost:8080", Value: "http://localhost:8080",
},
cli.StringFlag{
Name: "scheme",
Usage: "http/https",
Destination: &c.Scheme,
EnvVar: "SCHEME",
Value: "http",
}, },
} }
} }

View File

@@ -93,7 +93,9 @@ func (p publishcmd) dockerpush(image string) error {
} }
func (p *publishcmd) route(path string, ff *funcfile) error { func (p *publishcmd) route(path string, ff *funcfile) error {
resetBasePath(&p.Configuration) if err := resetBasePath(&p.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
an, r := extractAppNameRoute(path) an, r := extractAppNameRoute(path)
if ff.App == nil { if ff.App == nil {

View File

@@ -73,7 +73,9 @@ func (a *routesCmd) list(c *cli.Context) error {
return errors.New("error: routes listing takes one argument, an app name") return errors.New("error: routes listing takes one argument, an app name")
} }
resetBasePath(&a.Configuration) if err := resetBasePath(&a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
appName := c.Args().Get(0) appName := c.Args().Get(0)
wrapper, _, err := a.AppsAppRoutesGet(appName) wrapper, _, err := a.AppsAppRoutesGet(appName)
@@ -107,7 +109,9 @@ func (a *routesCmd) call(c *cli.Context) error {
return errors.New("error: routes listing takes three arguments: an app name and a route") return errors.New("error: routes listing takes three arguments: an app name and a route")
} }
resetBasePath(&a.Configuration) if err := resetBasePath(&a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
baseURL, err := url.Parse(a.Configuration.BasePath) baseURL, err := url.Parse(a.Configuration.BasePath)
if err != nil { if err != nil {
@@ -160,7 +164,9 @@ func (a *routesCmd) create(c *cli.Context) error {
return errors.New("error: routes listing takes three arguments: an app name, a route path and an image") return errors.New("error: routes listing takes three arguments: an app name, a route path and an image")
} }
resetBasePath(&a.Configuration) if err := resetBasePath(&a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
appName := c.Args().Get(0) appName := c.Args().Get(0)
route := c.Args().Get(1) route := c.Args().Get(1)
@@ -189,7 +195,9 @@ func (a *routesCmd) delete(c *cli.Context) error {
return errors.New("error: routes listing takes three arguments: an app name and a path") return errors.New("error: routes listing takes three arguments: an app name and a path")
} }
resetBasePath(&a.Configuration) if err := resetBasePath(&a.Configuration); err != nil {
return fmt.Errorf("error setting endpoint: %v", err)
}
appName := c.Args().Get(0) appName := c.Args().Get(0)
route := c.Args().Get(1) route := c.Args().Get(1)