From 77a2af8817284d134ea1f30f0b06291a5b05c5a0 Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Mon, 23 Mar 2020 10:27:32 -0700 Subject: Combine GlobalFlags and EngineFlags into EngineOptions * EngineOptions obtained in command via `opt, err := registry.Options(cmd)` Signed-off-by: Jhon Honce --- cmd/podmanV2/registry/registry.go | 28 ++++++++++++++++++++++------ cmd/podmanV2/registry/remote.go | 9 +++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 cmd/podmanV2/registry/remote.go (limited to 'cmd/podmanV2/registry') 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 +} -- cgit v1.2.3-54-g00ecf