From e68df5d154113cfb9b90ad79e5a1ed9fdb824b00 Mon Sep 17 00:00:00 2001 From: Pedro Nasser Date: Thu, 5 Jan 2017 16:00:31 -0200 Subject: [PATCH] changes in the fn organization and aliases (#475) --- fn/apps.go | 2 +- fn/images.go | 27 ++++++++++++++++++++++ fn/main.go | 63 ++++++++++++++++++++++++++++++++++++++++------------ fn/routes.go | 2 +- 4 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 fn/images.go diff --git a/fn/apps.go b/fn/apps.go index 1b4af0bea..dffeee948 100644 --- a/fn/apps.go +++ b/fn/apps.go @@ -21,7 +21,7 @@ func apps() cli.Command { return cli.Command{ Name: "apps", - Usage: "operate applications", + Usage: "manage applications", ArgsUsage: "fn apps", Subcommands: []cli.Command{ { diff --git a/fn/images.go b/fn/images.go new file mode 100644 index 000000000..03e08b83a --- /dev/null +++ b/fn/images.go @@ -0,0 +1,27 @@ +package main + +import ( + "github.com/iron-io/functions_go" + "github.com/urfave/cli" +) + +type imagesCmd struct { + *functions.AppsApi +} + +func images() cli.Command { + return cli.Command{ + Name: "images", + Usage: "manage function images", + ArgsUsage: "fn images", + Subcommands: []cli.Command{ + build(), + deploy(), + bump(), + call(), + push(), + run(), + testfn(), + }, + } +} diff --git a/fn/main.go b/fn/main.go index 507487508..a29cabf3b 100644 --- a/fn/main.go +++ b/fn/main.go @@ -9,33 +9,68 @@ import ( "github.com/urfave/cli" ) -const fnversion = "0.1.39" +const fnversion = "0.1.40" + +var aliases = map[string]cli.Command{ + "build": build(), + "bump": bump(), + "deploy": deploy(), +} + +func aliasesFn() []cli.Command { + cmds := []cli.Command{} + for alias, cmd := range aliases { + cmd.Name = alias + cmd.Hidden = true + cmds = append(cmds, cmd) + } + return cmds +} func main() { app := cli.NewApp() app.Name = "fn" app.Version = fnversion 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/fn/README.md + app.Description = "IronFunctions command line tools" + app.UsageText = `Check the manual at https://github.com/iron-io/functions/blob/master/fn/README.md` + + cli.AppHelpTemplate = `{{.Name}} {{.Version}}{{if .Description}} + +{{.Description}}{{end}} + +USAGE: + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} 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) } + API_URL - IronFunctions remote API address{{if .VisibleCommands}} + +COMMANDS:{{range .VisibleCategories}}{{if .Name}} + {{.Name}}:{{end}}{{range .VisibleCommands}} + {{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}} + +ALIASES: + build (images build) + bump (images bump) + deploy (images deploy) + +GLOBAL OPTIONS: + {{range $index, $option := .VisibleFlags}}{{if $index}} + {{end}}{{$option}}{{end}}{{end}} +` + + app.CommandNotFound = func(c *cli.Context, cmd string) { + fmt.Fprintf(os.Stderr, "command not found: %v\n", cmd) + } app.Commands = []cli.Command{ - apps(), - build(), - bump(), - call(), - deploy(), initFn(), - lambda(), - push(), + apps(), routes(), - run(), - testfn(), + images(), + lambda(), version(), } + app.Commands = append(app.Commands, aliasesFn()...) app.Run(os.Args) } diff --git a/fn/routes.go b/fn/routes.go index dbc2997b4..1fe944a75 100644 --- a/fn/routes.go +++ b/fn/routes.go @@ -27,7 +27,7 @@ func routes() cli.Command { return cli.Command{ Name: "routes", - Usage: "operate routes", + Usage: "manage routes", ArgsUsage: "fn routes", Subcommands: []cli.Command{ {