From 33944cefe7c1f3e11c8389bedb3e4c80af8541bd Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Tue, 18 May 2021 11:23:25 -0700 Subject: [Techinal Debt] Cleanup ABI vs. Tunnel CLI commands [NO TESTS NEEDED] This commit cleans up two issues: * Most commands support all EngineModes so default to that. Let outlayers declare their intent. * Use cobra.Annotations to set supported EngineMode. This simplies instantiating commands as there is now one method to communicate a commands requirements rather than two. * Combined aliased commands into one file * Fixed aliased commands where Args field did not match * Updated examples in README.md for writing commands * Remove redundant flag DisableFlagsInUseLine in cobra.Command initialization. Signed-off-by: Jhon Honce --- cmd/podman/system/connection.go | 17 +++++++---------- cmd/podman/system/connection/add.go | 2 -- cmd/podman/system/connection/default.go | 17 +++++++---------- cmd/podman/system/connection/list.go | 13 +++++-------- cmd/podman/system/connection/remove.go | 17 +++++++---------- cmd/podman/system/connection/rename.go | 17 +++++++---------- cmd/podman/system/df.go | 1 - cmd/podman/system/events.go | 1 - cmd/podman/system/info.go | 3 --- cmd/podman/system/migrate.go | 2 +- cmd/podman/system/prune.go | 1 - cmd/podman/system/renumber.go | 15 +++++++-------- cmd/podman/system/reset.go | 2 +- cmd/podman/system/service.go | 2 +- cmd/podman/system/system.go | 2 -- cmd/podman/system/unshare.go | 13 ++++++------- cmd/podman/system/version.go | 1 - 17 files changed, 49 insertions(+), 77 deletions(-) (limited to 'cmd/podman/system') diff --git a/cmd/podman/system/connection.go b/cmd/podman/system/connection.go index dbdda8cf9..1f8e8f13f 100644 --- a/cmd/podman/system/connection.go +++ b/cmd/podman/system/connection.go @@ -3,7 +3,6 @@ package system import ( "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/validate" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/spf13/cobra" ) @@ -14,20 +13,18 @@ var ( } ConnectionCmd = &cobra.Command{ - Use: "connection", - Short: "Manage remote ssh destinations", - Long: `Manage ssh destination information in podman configuration`, - DisableFlagsInUseLine: true, - PersistentPreRunE: noOp, - RunE: validate.SubCommandExists, - PersistentPostRunE: noOp, - TraverseChildren: false, + Use: "connection", + Short: "Manage remote ssh destinations", + Long: `Manage ssh destination information in podman configuration`, + PersistentPreRunE: noOp, + RunE: validate.SubCommandExists, + PersistentPostRunE: noOp, + TraverseChildren: false, } ) func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: ConnectionCmd, Parent: systemCmd, }) diff --git a/cmd/podman/system/connection/add.go b/cmd/podman/system/connection/add.go index 89d28849c..ecfeb6608 100644 --- a/cmd/podman/system/connection/add.go +++ b/cmd/podman/system/connection/add.go @@ -15,7 +15,6 @@ import ( "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/system" "github.com/containers/podman/v3/libpod/define" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/containers/podman/v3/pkg/terminal" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -53,7 +52,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: addCmd, Parent: system.ConnectionCmd, }) diff --git a/cmd/podman/system/connection/default.go b/cmd/podman/system/connection/default.go index 073bdbc3f..cfedc337b 100644 --- a/cmd/podman/system/connection/default.go +++ b/cmd/podman/system/connection/default.go @@ -7,27 +7,24 @@ import ( "github.com/containers/podman/v3/cmd/podman/common" "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/system" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/spf13/cobra" ) var ( // Skip creating engines since this command will obtain connection information to said engines dfltCmd = &cobra.Command{ - Use: "default NAME", - Args: cobra.ExactArgs(1), - Short: "Set named destination as default", - Long: `Set named destination as default for the Podman service`, - DisableFlagsInUseLine: true, - ValidArgsFunction: common.AutocompleteSystemConnections, - RunE: defaultRunE, - Example: `podman system connection default testing`, + Use: "default NAME", + Args: cobra.ExactArgs(1), + Short: "Set named destination as default", + Long: `Set named destination as default for the Podman service`, + ValidArgsFunction: common.AutocompleteSystemConnections, + RunE: defaultRunE, + Example: `podman system connection default testing`, } ) func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: dfltCmd, Parent: system.ConnectionCmd, }) diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go index fe7026ae3..ae88b0b30 100644 --- a/cmd/podman/system/connection/list.go +++ b/cmd/podman/system/connection/list.go @@ -10,18 +10,16 @@ import ( "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/system" "github.com/containers/podman/v3/cmd/podman/validate" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/spf13/cobra" ) var ( listCmd = &cobra.Command{ - Use: "list", - Aliases: []string{"ls"}, - Args: validate.NoArgs, - Short: "List destination for the Podman service(s)", - Long: `List destination information for the Podman service(s) in podman configuration`, - DisableFlagsInUseLine: true, + Use: "list", + Aliases: []string{"ls"}, + Args: validate.NoArgs, + Short: "List destination for the Podman service(s)", + Long: `List destination information for the Podman service(s) in podman configuration`, Example: `podman system connection list podman system connection ls`, ValidArgsFunction: completion.AutocompleteNone, @@ -32,7 +30,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: listCmd, Parent: system.ConnectionCmd, }) diff --git a/cmd/podman/system/connection/remove.go b/cmd/podman/system/connection/remove.go index 4acaa36a9..73bae4994 100644 --- a/cmd/podman/system/connection/remove.go +++ b/cmd/podman/system/connection/remove.go @@ -5,21 +5,19 @@ import ( "github.com/containers/podman/v3/cmd/podman/common" "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/system" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/spf13/cobra" ) var ( // Skip creating engines since this command will obtain connection information to said engines rmCmd = &cobra.Command{ - Use: "remove NAME", - Args: cobra.ExactArgs(1), - Aliases: []string{"rm"}, - Long: `Delete named destination from podman configuration`, - Short: "Delete named destination", - DisableFlagsInUseLine: true, - ValidArgsFunction: common.AutocompleteSystemConnections, - RunE: rm, + Use: "remove NAME", + Args: cobra.ExactArgs(1), + Aliases: []string{"rm"}, + Long: `Delete named destination from podman configuration`, + Short: "Delete named destination", + ValidArgsFunction: common.AutocompleteSystemConnections, + RunE: rm, Example: `podman system connection remove devl podman system connection rm devl`, } @@ -27,7 +25,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: rmCmd, Parent: system.ConnectionCmd, }) diff --git a/cmd/podman/system/connection/rename.go b/cmd/podman/system/connection/rename.go index 7713c2b09..898457d38 100644 --- a/cmd/podman/system/connection/rename.go +++ b/cmd/podman/system/connection/rename.go @@ -7,21 +7,19 @@ import ( "github.com/containers/podman/v3/cmd/podman/common" "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/system" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/spf13/cobra" ) var ( // Skip creating engines since this command will obtain connection information to said engines renameCmd = &cobra.Command{ - Use: "rename OLD NEW", - Aliases: []string{"mv"}, - Args: cobra.ExactArgs(2), - Short: "Rename \"old\" to \"new\"", - Long: `Rename destination for the Podman service from "old" to "new"`, - DisableFlagsInUseLine: true, - ValidArgsFunction: common.AutocompleteSystemConnections, - RunE: rename, + Use: "rename OLD NEW", + Aliases: []string{"mv"}, + Args: cobra.ExactArgs(2), + Short: "Rename \"old\" to \"new\"", + Long: `Rename destination for the Podman service from "old" to "new"`, + ValidArgsFunction: common.AutocompleteSystemConnections, + RunE: rename, Example: `podman system connection rename laptop devl, podman system connection mv laptop devl`, } @@ -29,7 +27,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: renameCmd, Parent: system.ConnectionCmd, }) diff --git a/cmd/podman/system/df.go b/cmd/podman/system/df.go index 5e179a82d..de56c57d0 100644 --- a/cmd/podman/system/df.go +++ b/cmd/podman/system/df.go @@ -40,7 +40,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: dfSystemCommand, Parent: systemCmd, }) diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go index 568610bdc..4aa413ec6 100644 --- a/cmd/podman/system/events.go +++ b/cmd/podman/system/events.go @@ -41,7 +41,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: eventsCommand, }) flags := eventsCommand.Flags() diff --git a/cmd/podman/system/info.go b/cmd/podman/system/info.go index 44be4ccec..1dc90f79a 100644 --- a/cmd/podman/system/info.go +++ b/cmd/podman/system/info.go @@ -11,7 +11,6 @@ import ( "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/validate" "github.com/containers/podman/v3/libpod/define" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/ghodss/yaml" "github.com/spf13/cobra" ) @@ -49,13 +48,11 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: infoCommand, }) infoFlags(infoCommand) registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: systemInfoCommand, Parent: systemCmd, }) diff --git a/cmd/podman/system/migrate.go b/cmd/podman/system/migrate.go index 892d60a38..9940cd063 100644 --- a/cmd/podman/system/migrate.go +++ b/cmd/podman/system/migrate.go @@ -22,6 +22,7 @@ var ( ` migrateCommand = &cobra.Command{ + Annotations: map[string]string{registry.EngineMode: registry.ABIMode}, Use: "migrate [options]", Args: validate.NoArgs, Short: "Migrate containers", @@ -37,7 +38,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode}, Command: migrateCommand, Parent: systemCmd, }) diff --git a/cmd/podman/system/prune.go b/cmd/podman/system/prune.go index 0f1285564..e09e2d5e5 100644 --- a/cmd/podman/system/prune.go +++ b/cmd/podman/system/prune.go @@ -41,7 +41,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: pruneCommand, Parent: systemCmd, }) diff --git a/cmd/podman/system/renumber.go b/cmd/podman/system/renumber.go index 91c49333a..83a873c2a 100644 --- a/cmd/podman/system/renumber.go +++ b/cmd/podman/system/renumber.go @@ -23,19 +23,18 @@ var ( ` renumberCommand = &cobra.Command{ - Use: "renumber", - Args: validate.NoArgs, - DisableFlagsInUseLine: true, - Short: "Migrate lock numbers", - Long: renumberDescription, - Run: renumber, - ValidArgsFunction: completion.AutocompleteNone, + Annotations: map[string]string{registry.EngineMode: registry.ABIMode}, + Use: "renumber", + Args: validate.NoArgs, + Short: "Migrate lock numbers", + Long: renumberDescription, + Run: renumber, + ValidArgsFunction: completion.AutocompleteNone, } ) func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode}, Command: renumberCommand, Parent: systemCmd, }) diff --git a/cmd/podman/system/reset.go b/cmd/podman/system/reset.go index 6f2f873dd..0edb36889 100644 --- a/cmd/podman/system/reset.go +++ b/cmd/podman/system/reset.go @@ -23,6 +23,7 @@ var ( All containers will be stopped and removed, and all images, volumes and container content will be removed. ` systemResetCommand = &cobra.Command{ + Annotations: map[string]string{registry.EngineMode: registry.ABIMode}, Use: "reset [options]", Args: validate.NoArgs, Short: "Reset podman storage", @@ -36,7 +37,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode}, Command: systemResetCommand, Parent: systemCmd, }) diff --git a/cmd/podman/system/service.go b/cmd/podman/system/service.go index 1e1cdbd12..63f2de51e 100644 --- a/cmd/podman/system/service.go +++ b/cmd/podman/system/service.go @@ -28,6 +28,7 @@ Enable a listening service for API access to Podman commands. ` srvCmd = &cobra.Command{ + Annotations: map[string]string{registry.EngineMode: registry.ABIMode}, Use: "service [options] [URI]", Args: cobra.MaximumNArgs(1), Short: "Run API service", @@ -44,7 +45,6 @@ Enable a listening service for API access to Podman commands. func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode}, Command: srvCmd, Parent: systemCmd, }) diff --git a/cmd/podman/system/system.go b/cmd/podman/system/system.go index ab06c3ae0..1947decaf 100644 --- a/cmd/podman/system/system.go +++ b/cmd/podman/system/system.go @@ -3,7 +3,6 @@ package system import ( "github.com/containers/podman/v3/cmd/podman/registry" "github.com/containers/podman/v3/cmd/podman/validate" - "github.com/containers/podman/v3/pkg/domain/entities" "github.com/spf13/cobra" ) @@ -22,7 +21,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: systemCmd, }) } diff --git a/cmd/podman/system/unshare.go b/cmd/podman/system/unshare.go index c07751532..f930d8b62 100644 --- a/cmd/podman/system/unshare.go +++ b/cmd/podman/system/unshare.go @@ -15,12 +15,12 @@ var ( unshareOptions = entities.SystemUnshareOptions{} unshareDescription = "Runs a command in a modified user namespace." unshareCommand = &cobra.Command{ - Use: "unshare [options] [COMMAND [ARG...]]", - DisableFlagsInUseLine: true, - Short: "Run a command in a modified user namespace", - Long: unshareDescription, - RunE: unshare, - ValidArgsFunction: completion.AutocompleteDefault, + Annotations: map[string]string{registry.EngineMode: registry.ABIMode}, + Use: "unshare [options] [COMMAND [ARG...]]", + Short: "Run a command in a modified user namespace", + Long: unshareDescription, + RunE: unshare, + ValidArgsFunction: completion.AutocompleteDefault, Example: `podman unshare id podman unshare cat /proc/self/uid_map, podman unshare podman-script.sh`, @@ -29,7 +29,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode}, Command: unshareCommand, }) flags := unshareCommand.Flags() diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go index ad9fd2a85..5575fc87d 100644 --- a/cmd/podman/system/version.go +++ b/cmd/podman/system/version.go @@ -31,7 +31,6 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: versionCommand, }) flags := versionCommand.Flags() -- cgit v1.2.3-54-g00ecf