Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes #608. Added snapctl t:n:v option.
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyfay committed Dec 9, 2015
1 parent aa608fa commit fa145bd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cmd/snapctl/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ var (
Subcommands: []cli.Command{
{
Name: "load",
Usage: "load <plugin path>",
Usage: "load <plugin_path>",
Action: loadPlugin,
Flags: []cli.Flag{
flPluginAsc,
},
},
{
Name: "unload",
Usage: "unload",
Usage: "unload <plugin_type>:<plugin_name>:<plugin_version> or unload -t <plugin_type> -n <plugin_version> -v <plugin_version>",
Action: unloadPlugin,
Flags: []cli.Flag{
flPluginType,
Expand Down Expand Up @@ -200,7 +200,7 @@ var (
Subcommands: []cli.Command{
{
Name: "get",
Usage: "get",
Usage: "get <plugin_type>:<plugin_name>:<plugin_version> or unload -t <plugin_type> -n <plugin_version> -v <plugin_version>",
Action: getConfig,
Flags: []cli.Flag{
flPluginName,
Expand Down
41 changes: 38 additions & 3 deletions cmd/snapctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ limitations under the License.
package main

import (
"fmt"
"os"
"path/filepath"
"strconv"
"text/tabwriter"

Expand All @@ -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,
Expand Down
30 changes: 27 additions & 3 deletions cmd/snapctl/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package main
import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"text/tabwriter"
"time"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fa145bd

Please sign in to comment.