summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podmanV2/containers/kill.go2
-rw-r--r--cmd/podmanV2/containers/pause.go2
-rw-r--r--cmd/podmanV2/containers/restart.go2
-rw-r--r--cmd/podmanV2/containers/rm.go2
-rw-r--r--cmd/podmanV2/containers/stop.go2
-rw-r--r--cmd/podmanV2/containers/unpause.go2
-rw-r--r--cmd/podmanV2/containers/wait.go2
-rw-r--r--cmd/podmanV2/images/inspect.go2
-rw-r--r--cmd/podmanV2/images/list.go1
-rw-r--r--cmd/podmanV2/main.go8
-rw-r--r--cmd/podmanV2/registry/registry.go28
-rw-r--r--cmd/podmanV2/registry/remote.go9
-rw-r--r--cmd/podmanV2/root.go7
-rw-r--r--cmd/podmanV2/utils/remote.go10
14 files changed, 48 insertions, 31 deletions
diff --git a/cmd/podmanV2/containers/kill.go b/cmd/podmanV2/containers/kill.go
index b02dcf9da..36c4f2528 100644
--- a/cmd/podmanV2/containers/kill.go
+++ b/cmd/podmanV2/containers/kill.go
@@ -41,7 +41,7 @@ func init() {
flags.BoolVarP(&killOptions.All, "all", "a", false, "Signal all running containers")
flags.StringVarP(&killOptions.Signal, "signal", "s", "KILL", "Signal to send to the container")
flags.BoolVarP(&killOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
- if utils.IsRemote() {
+ if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
}
diff --git a/cmd/podmanV2/containers/pause.go b/cmd/podmanV2/containers/pause.go
index 3f3e7c38d..99ca34d5c 100644
--- a/cmd/podmanV2/containers/pause.go
+++ b/cmd/podmanV2/containers/pause.go
@@ -42,7 +42,7 @@ func pause(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
- if rootless.IsRootless() && !utils.IsRemote() {
+ if rootless.IsRootless() && !registry.IsRemote() {
return errors.New("pause is not supported for rootless containers")
}
if len(args) < 1 && !pauseOpts.All {
diff --git a/cmd/podmanV2/containers/restart.go b/cmd/podmanV2/containers/restart.go
index ee9c34361..216824389 100644
--- a/cmd/podmanV2/containers/restart.go
+++ b/cmd/podmanV2/containers/restart.go
@@ -47,7 +47,7 @@ func init() {
flags.BoolVar(&restartOptions.Running, "running", false, "Restart only running containers when --all is used")
flags.UintVarP(&restartTimeout, "timeout", "t", define.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
flags.UintVar(&restartTimeout, "time", define.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
- if utils.IsRemote() {
+ if registry.IsRemote() {
_ = flags.MarkHidden("latest")
}
}
diff --git a/cmd/podmanV2/containers/rm.go b/cmd/podmanV2/containers/rm.go
index af7a38fb1..916dd2577 100644
--- a/cmd/podmanV2/containers/rm.go
+++ b/cmd/podmanV2/containers/rm.go
@@ -50,7 +50,7 @@ func init() {
flags.BoolVar(&rmOptions.Storage, "storage", false, "Remove container from storage library")
flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container")
flags.StringArrayVarP(&rmOptions.CIDFiles, "cidfile", "", nil, "Read the container ID from the file")
- if utils.IsRemote() {
+ if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore")
_ = flags.MarkHidden("cidfile")
diff --git a/cmd/podmanV2/containers/stop.go b/cmd/podmanV2/containers/stop.go
index 066202298..b6d70784d 100644
--- a/cmd/podmanV2/containers/stop.go
+++ b/cmd/podmanV2/containers/stop.go
@@ -48,7 +48,7 @@ func init() {
flags.BoolVarP(&stopOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.UintVar(&stopTimeout, "time", define.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
flags.UintVarP(&stopTimeout, "timeout", "t", define.CtrRemoveTimeout, "Seconds to wait for stop before killing the container")
- if registry.EngineOpts.EngineMode == entities.ABIMode {
+ if registry.EngineOptions.EngineMode == entities.ABIMode {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("cidfile")
_ = flags.MarkHidden("ignore")
diff --git a/cmd/podmanV2/containers/unpause.go b/cmd/podmanV2/containers/unpause.go
index 697132a53..8b8cde9b2 100644
--- a/cmd/podmanV2/containers/unpause.go
+++ b/cmd/podmanV2/containers/unpause.go
@@ -39,7 +39,7 @@ func unpause(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
- if rootless.IsRootless() && !utils.IsRemote() {
+ if rootless.IsRootless() && !registry.IsRemote() {
return errors.New("unpause is not supported for rootless containers")
}
if len(args) < 1 && !unPauseOptions.All {
diff --git a/cmd/podmanV2/containers/wait.go b/cmd/podmanV2/containers/wait.go
index cded8e571..4367fd9d9 100644
--- a/cmd/podmanV2/containers/wait.go
+++ b/cmd/podmanV2/containers/wait.go
@@ -46,7 +46,7 @@ func init() {
flags.DurationVarP(&waitOptions.Interval, "interval", "i", time.Duration(250), "Milliseconds to wait before polling for completion")
flags.BoolVarP(&waitOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
flags.StringVar(&waitCondition, "condition", "stopped", "Condition to wait on")
- if registry.EngineOpts.EngineMode == entities.ABIMode {
+ if registry.EngineOptions.EngineMode == entities.ABIMode {
// TODO: This is the same as V1. We could skip creating the flag altogether in V2...
_ = flags.MarkHidden("latest")
}
diff --git a/cmd/podmanV2/images/inspect.go b/cmd/podmanV2/images/inspect.go
index 2ecbbb201..f8fd44571 100644
--- a/cmd/podmanV2/images/inspect.go
+++ b/cmd/podmanV2/images/inspect.go
@@ -52,7 +52,7 @@ func init() {
flags.BoolVarP(&inspectOpts.Size, "size", "s", false, "Display total file size")
flags.StringVarP(&inspectOpts.Format, "format", "f", "", "Change the output format to a Go template")
- if registry.EngineOpts.EngineMode == entities.ABIMode {
+ if registry.EngineOptions.EngineMode == entities.ABIMode {
// TODO: This is the same as V1. We could skip creating the flag altogether in V2...
_ = flags.MarkHidden("latest")
}
diff --git a/cmd/podmanV2/images/list.go b/cmd/podmanV2/images/list.go
index cfdfaaed2..0441f8fd8 100644
--- a/cmd/podmanV2/images/list.go
+++ b/cmd/podmanV2/images/list.go
@@ -29,5 +29,6 @@ func init() {
}
func images(cmd *cobra.Command, args []string) error {
+ _, _ = registry.Options(cmd)
return nil
}
diff --git a/cmd/podmanV2/main.go b/cmd/podmanV2/main.go
index 24f21d804..dc96c26d0 100644
--- a/cmd/podmanV2/main.go
+++ b/cmd/podmanV2/main.go
@@ -32,9 +32,9 @@ func initCobra() {
case "darwin":
fallthrough
case "windows":
- registry.EngineOpts.EngineMode = entities.TunnelMode
+ registry.EngineOptions.EngineMode = entities.TunnelMode
case "linux":
- registry.EngineOpts.EngineMode = entities.ABIMode
+ registry.EngineOptions.EngineMode = entities.ABIMode
default:
logrus.Errorf("%s is not a supported OS", runtime.GOOS)
os.Exit(1)
@@ -43,7 +43,7 @@ func initCobra() {
// TODO: Is there a Cobra way to "peek" at os.Args?
for _, v := range os.Args {
if strings.HasPrefix(v, "--remote") {
- registry.EngineOpts.EngineMode = entities.TunnelMode
+ registry.EngineOptions.EngineMode = entities.TunnelMode
}
}
@@ -53,7 +53,7 @@ func initCobra() {
func main() {
fmt.Fprintf(os.Stderr, "Number of commands: %d\n", len(registry.Commands))
for _, c := range registry.Commands {
- if Contains(registry.EngineOpts.EngineMode, c.Mode) {
+ if Contains(registry.EngineOptions.EngineMode, c.Mode) {
parent := rootCmd
if c.Parent != nil {
parent = c.Parent
diff --git a/cmd/podmanV2/registry/registry.go b/cmd/podmanV2/registry/registry.go
index b0c11ba04..9c12b2456 100644
--- a/cmd/podmanV2/registry/registry.go
+++ b/cmd/podmanV2/registry/registry.go
@@ -1,6 +1,8 @@
package registry
import (
+ "context"
+
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/domain/infra"
@@ -20,8 +22,7 @@ var (
imageEngine entities.ImageEngine
containerEngine entities.ContainerEngine
- EngineOpts entities.EngineOptions
- GlobalFlags entities.EngineFlags
+ EngineOptions entities.EngineOptions
ExitCode = define.ExecErrorCodeGeneric
)
@@ -76,8 +77,8 @@ func ImageEngine() entities.ImageEngine {
// NewImageEngine is a wrapper for building an ImageEngine to be used for PreRunE functions
func NewImageEngine(cmd *cobra.Command, args []string) (entities.ImageEngine, error) {
if imageEngine == nil {
- EngineOpts.FlagSet = cmd.Flags()
- engine, err := infra.NewImageEngine(EngineOpts)
+ EngineOptions.FlagSet = cmd.Flags()
+ engine, err := infra.NewImageEngine(EngineOptions)
if err != nil {
return nil, err
}
@@ -93,8 +94,8 @@ func ContainerEngine() entities.ContainerEngine {
// NewContainerEngine is a wrapper for building an ContainerEngine to be used for PreRunE functions
func NewContainerEngine(cmd *cobra.Command, args []string) (entities.ContainerEngine, error) {
if containerEngine == nil {
- EngineOpts.FlagSet = cmd.Flags()
- engine, err := infra.NewContainerEngine(EngineOpts)
+ EngineOptions.FlagSet = cmd.Flags()
+ engine, err := infra.NewContainerEngine(EngineOptions)
if err != nil {
return nil, err
}
@@ -109,3 +110,18 @@ func SubCommandExists(cmd *cobra.Command, args []string) error {
}
return errors.Errorf("missing command '%[1]s COMMAND'\nTry '%[1]s --help' for more information.", cmd.CommandPath())
}
+
+type podmanContextKey string
+
+var podmanFactsKey = podmanContextKey("engineOptions")
+
+func NewOptions(ctx context.Context, facts *entities.EngineOptions) context.Context {
+ return context.WithValue(ctx, podmanFactsKey, facts)
+}
+
+func Options(cmd *cobra.Command) (*entities.EngineOptions, error) {
+ if f, ok := cmd.Context().Value(podmanFactsKey).(*entities.EngineOptions); ok {
+ return f, errors.New("Command Context ")
+ }
+ return nil, nil
+}
diff --git a/cmd/podmanV2/registry/remote.go b/cmd/podmanV2/registry/remote.go
new file mode 100644
index 000000000..32a231ac4
--- /dev/null
+++ b/cmd/podmanV2/registry/remote.go
@@ -0,0 +1,9 @@
+package registry
+
+import (
+ "github.com/containers/libpod/pkg/domain/entities"
+)
+
+func IsRemote() bool {
+ return EngineOptions.EngineMode == entities.TunnelMode
+}
diff --git a/cmd/podmanV2/root.go b/cmd/podmanV2/root.go
index 2becd126d..68e8b4531 100644
--- a/cmd/podmanV2/root.go
+++ b/cmd/podmanV2/root.go
@@ -26,12 +26,13 @@ func init() {
var dummyVersion bool
// TODO had to disable shorthand -v for version due to -v rm with volume
rootCmd.PersistentFlags().BoolVar(&dummyVersion, "version", false, "Version of Podman")
- rootCmd.PersistentFlags().StringVarP(&registry.EngineOpts.Uri, "remote", "r", "", "URL to access Podman service")
- rootCmd.PersistentFlags().StringSliceVar(&registry.EngineOpts.Identities, "identity", []string{}, "path to SSH identity file")
+ rootCmd.PersistentFlags().StringVarP(&registry.EngineOptions.Uri, "remote", "r", "", "URL to access Podman service")
+ rootCmd.PersistentFlags().StringSliceVar(&registry.EngineOptions.Identities, "identity", []string{}, "path to SSH identity file")
}
func Execute() {
- if err := rootCmd.Execute(); err != nil {
+ o := registry.NewOptions(rootCmd.Context(), &registry.EngineOptions)
+ if err := rootCmd.ExecuteContext(o); err != nil {
fmt.Fprintln(os.Stderr, "Error:", err.Error())
} else if registry.GetExitCode() == define.ExecErrorCodeGeneric {
// The exitCode modified from define.ExecErrorCodeGeneric,
diff --git a/cmd/podmanV2/utils/remote.go b/cmd/podmanV2/utils/remote.go
deleted file mode 100644
index d0c8a272d..000000000
--- a/cmd/podmanV2/utils/remote.go
+++ /dev/null
@@ -1,10 +0,0 @@
-package utils
-
-import (
- "github.com/containers/libpod/cmd/podmanV2/registry"
- "github.com/containers/libpod/pkg/domain/entities"
-)
-
-func IsRemote() bool {
- return registry.EngineOpts.EngineMode == entities.TunnelMode
-}