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/sign.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/sign.go')
-rw-r--r-- | cmd/podman/sign.go | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/cmd/podman/sign.go b/cmd/podman/sign.go index 22aa07230..a87c12556 100644 --- a/cmd/podman/sign.go +++ b/cmd/podman/sign.go @@ -11,60 +11,63 @@ import ( "github.com/containers/image/signature" "github.com/containers/image/transports" "github.com/containers/image/transports/alltransports" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/libpod/image" "github.com/containers/libpod/pkg/trust" "github.com/pkg/errors" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) var ( - signFlags = []cli.Flag{ - cli.StringFlag{ - Name: "sign-by", - Usage: "Name of the signing key", - }, - cli.StringFlag{ - Name: "directory, d", - Usage: "Define an alternate directory to store signatures", - }, - } - + signCommand cliconfig.SignValues signDescription = "Create a signature file that can be used later to verify the image" - signCommand = cli.Command{ - Name: "sign", - Usage: "Sign an image", - Description: signDescription, - Flags: sortFlags(signFlags), - Action: signCmd, - ArgsUsage: "IMAGE-NAME [IMAGE-NAME ...]", - OnUsageError: usageErrorHandler, + _signCommand = &cobra.Command{ + Use: "sign", + Short: "Sign an image", + Long: signDescription, + RunE: func(cmd *cobra.Command, args []string) error { + signCommand.InputArgs = args + signCommand.GlobalFlags = MainGlobalOpts + return signCmd(&signCommand) + }, + Example: "IMAGE-NAME [IMAGE-NAME ...]", } ) +func init() { + signCommand.Command = _signCommand + flags := signCommand.Flags() + flags.StringVarP(&signCommand.Directory, "directory", "d", "", "Define an alternate directory to store signatures") + flags.StringVar(&signCommand.SignBy, "sign-by", "", "Name of the signing key") + + rootCmd.AddCommand(signCommand.Command) + +} + // SignatureStoreDir defines default directory to store signatures const SignatureStoreDir = "/var/lib/containers/sigstore" -func signCmd(c *cli.Context) error { - args := c.Args() +func signCmd(c *cliconfig.SignValues) error { + args := c.InputArgs if len(args) < 1 { return errors.Errorf("at least one image name must be specified") } - runtime, err := libpodruntime.GetRuntime(c) + runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not create runtime") } defer runtime.Shutdown(false) - signby := c.String("sign-by") + signby := c.SignBy if signby == "" { return errors.Errorf("please provide an identity") } var sigStoreDir string - if c.IsSet("directory") { - sigStoreDir = c.String("directory") + if c.Flag("directory").Changed { + sigStoreDir = c.Directory if _, err := os.Stat(sigStoreDir); err != nil { return errors.Wrapf(err, "invalid directory %s", sigStoreDir) } |