Skip to content

Commit

Permalink
Switch to urfave/cli/v2
Browse files Browse the repository at this point in the history
The latest release of the command line parser has some breaking changes
which are included in this commit as well.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
  • Loading branch information
saschagrunert committed Dec 9, 2019
1 parent 4497522 commit c692cc4
Show file tree
Hide file tree
Showing 61 changed files with 2,195 additions and 1,906 deletions.
19 changes: 10 additions & 9 deletions cmd/crictl/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ import (
"net/url"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"golang.org/x/net/context"
pb "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
)

var runtimeAttachCommand = cli.Command{
var runtimeAttachCommand = &cli.Command{
Name: "attach",
Usage: "Attach to a running container",
ArgsUsage: "CONTAINER-ID",
SkipArgReorder: true,
UseShortOptionHandling: true,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "tty,t",
Usage: "Allocate a pseudo-TTY",
&cli.BoolFlag{
Name: "tty",
Aliases: []string{"t"},
Usage: "Allocate a pseudo-TTY",
},
cli.BoolFlag{
Name: "stdin,i",
Usage: "Keep STDIN open",
&cli.BoolFlag{
Name: "stdin",
Aliases: []string{"i"},
Usage: "Keep STDIN open",
},
},
Action: func(context *cli.Context) error {
Expand Down
8 changes: 4 additions & 4 deletions cmd/crictl/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"strings"

"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

var bashCompletionTemplate = `_cli_bash_autocomplete() {
Expand All @@ -47,7 +47,7 @@ func bashCompletion(c *cli.Context) error {

for _, flag := range c.App.Flags {
// only includes full flag name.
subcommands = append(subcommands, "--"+strings.Split(flag.GetName(), ",")[0])
subcommands = append(subcommands, "--"+flag.Names()[0])
}

fmt.Fprintln(c.App.Writer, fmt.Sprintf(bashCompletionTemplate, strings.Join(subcommands, "\n")))
Expand Down Expand Up @@ -83,15 +83,15 @@ func zshCompletion(c *cli.Context) error {
opts := []string{}
for _, flag := range c.App.Flags {
// only includes full flag name.
opts = append(opts, "--"+strings.Split(flag.GetName(), ",")[0])
opts = append(opts, "--"+flag.Names()[0])
}

fmt.Fprintln(c.App.Writer, fmt.Sprintf(zshCompletionTemplate, strings.Join(subcommands, "' '"), strings.Join(opts, "' '")))
return nil

}

var completionCommand = cli.Command{
var completionCommand = &cli.Command{
Name: "completion",
Usage: "Output shell completion code",
ArgsUsage: "SHELL",
Expand Down
9 changes: 4 additions & 5 deletions cmd/crictl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strconv"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -63,20 +63,19 @@ func writeConfig(c *Config, filepath string) error {
return ioutil.WriteFile(filepath, data, 0644)
}

var configCommand = cli.Command{
var configCommand = &cli.Command{
Name: "config",
Usage: "Get and set crictl options",
ArgsUsage: "[<options>]",
SkipArgReorder: true,
UseShortOptionHandling: true,
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "get",
Usage: "get value: name",
},
},
Action: func(context *cli.Context) error {
configFile := context.GlobalString("config")
configFile := context.String("config")
if _, err := os.Stat(configFile); err != nil {
if err := writeConfig(nil, configFile); err != nil {
return err
Expand Down
Loading

0 comments on commit c692cc4

Please sign in to comment.