From fa145bd73c8b1958e77623e69f2458a2a10dea79 Mon Sep 17 00:00:00 2001 From: Tiffany Jernigan Date: Tue, 8 Dec 2015 23:20:49 -0800 Subject: [PATCH] Fixes #608. Added snapctl t:n:v option. --- cmd/snapctl/commands.go | 6 +++--- cmd/snapctl/config.go | 41 ++++++++++++++++++++++++++++++++++++++--- cmd/snapctl/plugin.go | 30 +++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/cmd/snapctl/commands.go b/cmd/snapctl/commands.go index 6d0c60e08..a0371c5f2 100644 --- a/cmd/snapctl/commands.go +++ b/cmd/snapctl/commands.go @@ -92,7 +92,7 @@ var ( Subcommands: []cli.Command{ { Name: "load", - Usage: "load ", + Usage: "load ", Action: loadPlugin, Flags: []cli.Flag{ flPluginAsc, @@ -100,7 +100,7 @@ var ( }, { Name: "unload", - Usage: "unload", + Usage: "unload :: or unload -t -n -v ", Action: unloadPlugin, Flags: []cli.Flag{ flPluginType, @@ -200,7 +200,7 @@ var ( Subcommands: []cli.Command{ { Name: "get", - Usage: "get", + Usage: "get :: or unload -t -n -v ", Action: getConfig, Flags: []cli.Flag{ flPluginName, diff --git a/cmd/snapctl/config.go b/cmd/snapctl/config.go index fcd6033ee..672c1bfdf 100644 --- a/cmd/snapctl/config.go +++ b/cmd/snapctl/config.go @@ -20,7 +20,9 @@ limitations under the License. package main import ( + "fmt" "os" + "path/filepath" "strconv" "text/tabwriter" @@ -29,9 +31,42 @@ import ( ) func getConfig(ctx *cli.Context) { - ptyp := ctx.String("plugin-type") - pname := ctx.String("plugin-name") - pver := ctx.Int("plugin-version") + pDetails := filepath.SplitList(ctx.Args().First()) + var ptyp string + var pname string + var pver int + var err error + + if len(pDetails) == 3 { + ptyp = pDetails[0] + pname = pDetails[1] + pver, err = strconv.Atoi(pDetails[2]) + if err != nil { + fmt.Println("Can't convert version string to integer") + cli.ShowCommandHelp(ctx, ctx.Command.Name) + os.Exit(1) + } + } else { + ptyp = ctx.String("plugin-type") + pname = ctx.String("plugin-name") + pver = ctx.Int("plugin-version") + } + + if ptyp == "" { + fmt.Println("Must provide plugin type") + cli.ShowCommandHelp(ctx, ctx.Command.Name) + os.Exit(1) + } + if pname == "" { + fmt.Println("Must provide plugin name") + cli.ShowCommandHelp(ctx, ctx.Command.Name) + os.Exit(1) + } + if pver < 1 { + fmt.Println("Must provide plugin version") + cli.ShowCommandHelp(ctx, ctx.Command.Name) + os.Exit(1) + } w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0) defer w.Flush() printFields(w, false, 0, diff --git a/cmd/snapctl/plugin.go b/cmd/snapctl/plugin.go index d89fa1e65..ffb6c8797 100644 --- a/cmd/snapctl/plugin.go +++ b/cmd/snapctl/plugin.go @@ -22,6 +22,8 @@ package main import ( "fmt" "os" + "path/filepath" + "strconv" "strings" "text/tabwriter" "time" @@ -66,9 +68,31 @@ func loadPlugin(ctx *cli.Context) { } func unloadPlugin(ctx *cli.Context) { - pType := ctx.String("plugin-type") - pName := ctx.String("plugin-name") - pVer := ctx.Int("plugin-version") + pDetails := filepath.SplitList(ctx.Args().First()) + var pType string + var pName string + var pVer int + var err error + + if len(pDetails) == 3 { + pType = pDetails[0] + pName = pDetails[1] + pVer, err = strconv.Atoi(pDetails[2]) + if err != nil { + fmt.Println("Can't convert version string to integer") + cli.ShowCommandHelp(ctx, ctx.Command.Name) + os.Exit(1) + } + } else { + pType = ctx.String("plugin-type") + pName = ctx.String("plugin-name") + pVer = ctx.Int("plugin-version") + } + if pType == "" { + fmt.Println("Must provide plugin type") + cli.ShowCommandHelp(ctx, ctx.Command.Name) + os.Exit(1) + } if pName == "" { fmt.Println("Must provide plugin name") cli.ShowCommandHelp(ctx, ctx.Command.Name)