diff options
author | baude <bbaude@redhat.com> | 2019-01-31 13:20:04 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-02-08 10:26:43 -0600 |
commit | 25a3923b61a5ca014318e6d957f68abd03947297 (patch) | |
tree | 2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/generate_kube.go | |
parent | 962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff) | |
download | podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2 podman-25a3923b61a5ca014318e6d957f68abd03947297.zip |
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the
project is more well maintained. There are also some technical reasons
as well which extend into our remote client work.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/generate_kube.go')
-rw-r--r-- | cmd/podman/generate_kube.go | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/cmd/podman/generate_kube.go b/cmd/podman/generate_kube.go index fc667fb5b..8e3432d12 100644 --- a/cmd/podman/generate_kube.go +++ b/cmd/podman/generate_kube.go @@ -2,38 +2,40 @@ package main import ( "fmt" - + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/libpod" "github.com/containers/libpod/pkg/rootless" podmanVersion "github.com/containers/libpod/version" "github.com/ghodss/yaml" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/spf13/cobra" "k8s.io/api/core/v1" ) var ( - containerKubeFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "service, s", - Usage: "Generate YAML for kubernetes service object", - }, - } + containerKubeCommand cliconfig.GenerateKubeValues containerKubeDescription = "Generate Kubernetes Pod YAML" - containerKubeCommand = cli.Command{ - Name: "kube", - Usage: "Generate Kubernetes pod YAML for a container or pod", - Description: containerKubeDescription, - Flags: sortFlags(containerKubeFlags), - Action: generateKubeYAMLCmd, - ArgsUsage: "CONTAINER|POD-NAME", - UseShortOptionHandling: true, - OnUsageError: usageErrorHandler, + _containerKubeCommand = &cobra.Command{ + Use: "kube", + Short: "Generate Kubernetes pod YAML for a container or pod", + Long: containerKubeDescription, + RunE: func(cmd *cobra.Command, args []string) error { + containerKubeCommand.InputArgs = args + containerKubeCommand.GlobalFlags = MainGlobalOpts + return generateKubeYAMLCmd(&containerKubeCommand) + }, + Example: "CONTAINER|POD-NAME", } ) -func generateKubeYAMLCmd(c *cli.Context) error { +func init() { + containerKubeCommand.Command = _containerKubeCommand + flags := containerKubeCommand.Flags() + flags.BoolVarP(&containerKubeCommand.Service, "service", "s", false, "Generate YAML for kubernetes service object") +} + +func generateKubeYAMLCmd(c *cliconfig.GenerateKubeValues) error { var ( podYAML *v1.Pod container *libpod.Container @@ -48,12 +50,12 @@ func generateKubeYAMLCmd(c *cli.Context) error { if rootless.IsRootless() { return errors.Wrapf(libpod.ErrNotImplemented, "rootless users") } - args := c.Args() + args := c.InputArgs if len(args) > 1 || (len(args) < 1 && !c.Bool("latest")) { return errors.Errorf("you must provide one container|pod ID or name or --latest") } - runtime, err := libpodruntime.GetRuntime(c) + runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") } @@ -77,7 +79,7 @@ func generateKubeYAMLCmd(c *cli.Context) error { return err } - if c.Bool("service") { + if c.Service { serviceYAML := libpod.GenerateKubeServiceFromV1Pod(podYAML, servicePorts) marshalledService, err = yaml.Marshal(serviceYAML) if err != nil { |