diff options
Diffstat (limited to 'cmd/podmanV2/registry/registry.go')
-rw-r--r-- | cmd/podmanV2/registry/registry.go | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/cmd/podmanV2/registry/registry.go b/cmd/podmanV2/registry/registry.go index 793d520a8..5cdb8a840 100644 --- a/cmd/podmanV2/registry/registry.go +++ b/cmd/podmanV2/registry/registry.go @@ -1,12 +1,17 @@ package registry import ( + "context" + + "github.com/containers/libpod/libpod/define" "github.com/containers/libpod/pkg/domain/entities" "github.com/containers/libpod/pkg/domain/infra" "github.com/pkg/errors" "github.com/spf13/cobra" ) +type CobraFuncs func(cmd *cobra.Command, args []string) error + type CliCommand struct { Mode []entities.EngineMode Command *cobra.Command @@ -18,11 +23,21 @@ var ( imageEngine entities.ImageEngine containerEngine entities.ContainerEngine + cliCtx context.Context + + EngineOptions entities.EngineOptions - EngineOpts entities.EngineOptions - GlobalFlags entities.EngineFlags + ExitCode = define.ExecErrorCodeGeneric ) +func SetExitCode(code int) { + ExitCode = code +} + +func GetExitCode() int { + return ExitCode +} + // HelpTemplate returns the help template for podman commands // This uses the short and long options. // command should not use this. @@ -65,8 +80,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 } @@ -82,8 +97,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 } @@ -98,3 +113,25 @@ 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 +} + +func GetContext() context.Context { + if cliCtx == nil { + cliCtx = context.TODO() + } + return cliCtx +} |