summaryrefslogtreecommitdiff
path: root/cmd/podman/logout.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/logout.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-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/logout.go')
-rw-r--r--cmd/podman/logout.go51
1 files changed, 27 insertions, 24 deletions
diff --git a/cmd/podman/logout.go b/cmd/podman/logout.go
index 3cdb606b5..02bde7857 100644
--- a/cmd/podman/logout.go
+++ b/cmd/podman/logout.go
@@ -4,53 +4,56 @@ import (
"fmt"
"github.com/containers/image/pkg/docker/config"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/libpod/common"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
var (
- logoutFlags = []cli.Flag{
- cli.StringFlag{
- Name: "authfile",
- Usage: "Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. Use REGISTRY_AUTH_FILE environment variable to override. ",
- },
- cli.BoolFlag{
- Name: "all, a",
- Usage: "Remove the cached credentials for all registries in the auth file",
- },
- }
+ logoutCommand cliconfig.LogoutValues
logoutDescription = "Remove the cached username and password for the registry."
- logoutCommand = cli.Command{
- Name: "logout",
- Usage: "Logout of a container registry",
- Description: logoutDescription,
- Flags: sortFlags(logoutFlags),
- Action: logoutCmd,
- ArgsUsage: "REGISTRY",
- OnUsageError: usageErrorHandler,
+ _logoutCommand = &cobra.Command{
+ Use: "logout",
+ Short: "Logout of a container registry",
+ Long: logoutDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ logoutCommand.InputArgs = args
+ logoutCommand.GlobalFlags = MainGlobalOpts
+ return logoutCmd(&logoutCommand)
+ },
+ Example: "REGISTRY",
}
)
+func init() {
+ logoutCommand.Command = _logoutCommand
+ flags := logoutCommand.Flags()
+ flags.BoolVarP(&logoutCommand.All, "all", "a", false, "Remove the cached credentials for all registries in the auth file")
+ flags.StringVar(&logoutCommand.Authfile, "authfile", "", "Path of the authentication file. Default is ${XDG_RUNTIME_DIR}/containers/auth.json. Use REGISTRY_AUTH_FILE environment variable to override")
+
+ rootCmd.AddCommand(logoutCommand.Command)
+}
+
// logoutCmd uses the authentication package to remove the authenticated of a registry
// stored in the auth.json file
-func logoutCmd(c *cli.Context) error {
- args := c.Args()
+func logoutCmd(c *cliconfig.LogoutValues) error {
+ args := c.InputArgs
if len(args) > 1 {
return errors.Errorf("too many arguments, logout takes at most 1 argument")
}
- if len(args) == 0 && !c.IsSet("all") {
+ if len(args) == 0 && !c.All {
return errors.Errorf("registry must be given")
}
var server string
if len(args) == 1 {
server = scrubServer(args[0])
}
- authfile := getAuthFile(c.String("authfile"))
+ authfile := getAuthFile(c.Authfile)
sc := common.GetSystemContext("", authfile, false)
- if c.Bool("all") {
+ if c.All {
if err := config.RemoveAllAuthentication(sc); err != nil {
return err
}