From d8bb2df85eb6f703394d0a003c040f2611e94c11 Mon Sep 17 00:00:00 2001 From: C Cirello Date: Fri, 11 Nov 2016 01:44:27 +0100 Subject: [PATCH] fnctl: improve help on how to configure remote server (#246) * fnctl: improve help on how to configure remote server Partially addresses #241 * fnctl: HOST/FNCTL_HOST -> API_URL * fnctl: improve help on how to configure remote server --- fnctl/README.md | 10 ++++++++++ fnctl/apps.go | 1 - fnctl/main.go | 24 ++++++++++-------------- fnctl/publish.go | 1 - fnctl/push.go | 1 - fnctl/routes.go | 8 ++------ 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/fnctl/README.md b/fnctl/README.md index 14deef99c..052e2e634 100644 --- a/fnctl/README.md +++ b/fnctl/README.md @@ -45,6 +45,16 @@ $ fnctl routes delete otherapp hello # delete route /hello deleted ``` +## Changing target host + +`fnctl` is configured by default to talk to a locally installed IronFunctions. +You may reconfigure it to talk to a remote installation by updating a local +environment variable (`$API_URL`): +```sh +$ export API_URL="http://myfunctions.example.org/" +$ fnctl ... +``` + ## Publish Also there is the publish command that is going to scan all local directory for diff --git a/fnctl/apps.go b/fnctl/apps.go index 015624b3e..54969a811 100644 --- a/fnctl/apps.go +++ b/fnctl/apps.go @@ -21,7 +21,6 @@ func apps() cli.Command { Name: "apps", Usage: "list apps", ArgsUsage: "fnctl apps", - Flags: append(confFlags(&a.Configuration), []cli.Flag{}...), Action: a.list, Subcommands: []cli.Command{ { diff --git a/fnctl/main.go b/fnctl/main.go index 2267894ea..c9bc0d4e5 100644 --- a/fnctl/main.go +++ b/fnctl/main.go @@ -15,7 +15,10 @@ func main() { app.Version = "0.0.1" app.Authors = []cli.Author{{Name: "iron.io"}} app.Usage = "IronFunctions command line tools" - app.UsageText = "Check the manual at https://github.com/iron-io/functions/blob/master/fnctl/README.md" + app.UsageText = `Check the manual at https://github.com/iron-io/functions/blob/master/fnctl/README.md + +ENVIRONMENT VARIABLES: + API_URL - IronFunctions remote API address` app.CommandNotFound = func(c *cli.Context, cmd string) { fmt.Fprintf(os.Stderr, "command not found: %v\n", cmd) } app.Commands = []cli.Command{ apps(), @@ -32,7 +35,12 @@ func main() { } func resetBasePath(c *functions.Configuration) error { - u, err := url.Parse(c.Host) + apiURL := os.Getenv("API_URL") + if apiURL == "" { + apiURL = "http://localhost:8080/" + } + + u, err := url.Parse(apiURL) if err != nil { return err } @@ -41,15 +49,3 @@ func resetBasePath(c *functions.Configuration) error { return nil } - -func confFlags(c *functions.Configuration) []cli.Flag { - return []cli.Flag{ - cli.StringFlag{ - Name: "endpoint", - Usage: "url to functions api endpoint e.g. http://functions.iron.io", - Destination: &c.Host, - EnvVar: "HOST", - Value: "http://localhost:8080", - }, - } -} diff --git a/fnctl/publish.go b/fnctl/publish.go index 31d56bfa2..8bb7b608c 100644 --- a/fnctl/publish.go +++ b/fnctl/publish.go @@ -20,7 +20,6 @@ func publish() cli.Command { var flags []cli.Flag flags = append(flags, cmd.flags()...) flags = append(flags, cmd.commoncmd.flags()...) - flags = append(flags, confFlags(&cmd.Configuration)...) return cli.Command{ Name: "publish", Usage: "scan local directory for functions, build and publish them.", diff --git a/fnctl/push.go b/fnctl/push.go index 59191b432..061f58e50 100644 --- a/fnctl/push.go +++ b/fnctl/push.go @@ -18,7 +18,6 @@ func push() cli.Command { } var flags []cli.Flag flags = append(flags, cmd.commoncmd.flags()...) - flags = append(flags, confFlags(&cmd.Configuration)...) return cli.Command{ Name: "push", Usage: "scan local directory for functions and push them.", diff --git a/fnctl/routes.go b/fnctl/routes.go index 6546569e7..8d5cd20af 100644 --- a/fnctl/routes.go +++ b/fnctl/routes.go @@ -23,12 +23,10 @@ type routesCmd struct { func routes() cli.Command { r := routesCmd{RoutesApi: functions.NewRoutesApi()} - flags := append(confFlags(&r.Configuration), []cli.Flag{}...) return cli.Command{ Name: "routes", Usage: "list routes", ArgsUsage: "fnctl routes", - Flags: flags, Action: r.list, Subcommands: []cli.Command{ { @@ -36,7 +34,7 @@ func routes() cli.Command { Usage: "call a route", ArgsUsage: "appName /path", Action: r.call, - Flags: append(flags, runflags()...), + Flags: runflags(), }, { Name: "create", @@ -73,13 +71,11 @@ func routes() cli.Command { func call() cli.Command { r := routesCmd{RoutesApi: functions.NewRoutesApi()} - flags := append([]cli.Flag{}, confFlags(&r.Configuration)...) - flags = append(flags, runflags()...) return cli.Command{ Name: "call", Usage: "call a remote function", ArgsUsage: "appName /path", - Flags: flags, + Flags: runflags(), Action: r.call, } }