summaryrefslogtreecommitdiff
path: root/cmd/podmanV2/registry/registry.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podmanV2/registry/registry.go')
-rw-r--r--cmd/podmanV2/registry/registry.go46
1 files changed, 26 insertions, 20 deletions
diff --git a/cmd/podmanV2/registry/registry.go b/cmd/podmanV2/registry/registry.go
index 401f82718..5ef6a10d8 100644
--- a/cmd/podmanV2/registry/registry.go
+++ b/cmd/podmanV2/registry/registry.go
@@ -9,7 +9,11 @@ import (
"github.com/spf13/cobra"
)
-type CobraFuncs func(cmd *cobra.Command, args []string) error
+// DefaultAPIAddress is the default address of the REST socket
+const DefaultAPIAddress = "unix:/run/podman/podman.sock"
+
+// DefaultVarlinkAddress is the default address of the varlink socket
+const DefaultVarlinkAddress = "unix:/run/podman/io.podman"
type CliCommand struct {
Mode []entities.EngineMode
@@ -25,8 +29,9 @@ var (
exitCode = ExecErrorCodeGeneric
imageEngine entities.ImageEngine
- Commands []CliCommand
- EngineOptions entities.EngineOptions
+ // Commands holds the cobra.Commands to present to the user, including
+ // parent if not a child of "root"
+ Commands []CliCommand
)
func SetExitCode(code int) {
@@ -79,8 +84,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 {
- EngineOptions.FlagSet = cmd.Flags()
- engine, err := infra.NewImageEngine(EngineOptions)
+ PodmanOptions.FlagSet = cmd.Flags()
+ engine, err := infra.NewImageEngine(PodmanOptions)
if err != nil {
return nil, err
}
@@ -96,8 +101,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 {
- EngineOptions.FlagSet = cmd.Flags()
- engine, err := infra.NewContainerEngine(EngineOptions)
+ PodmanOptions.FlagSet = cmd.Flags()
+ engine, err := infra.NewContainerEngine(PodmanOptions)
if err != nil {
return nil, err
}
@@ -113,24 +118,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 ")
+// IdOrLatestArgs used to validate a nameOrId was provided or the "--latest" flag
+func IdOrLatestArgs(cmd *cobra.Command, args []string) error {
+ if len(args) > 1 || (len(args) == 0 && !cmd.Flag("latest").Changed) {
+ return errors.New(`command requires a name, id or the "--latest" flag`)
}
- return nil, nil
+ return nil
}
func GetContext() context.Context {
if cliCtx == nil {
- cliCtx = context.TODO()
+ cliCtx = context.Background()
}
return cliCtx
}
+
+type ContextOptionsKey string
+
+const PodmanOptionsKey ContextOptionsKey = "PodmanOptions"
+
+func GetContextWithOptions() context.Context {
+ return context.WithValue(GetContext(), PodmanOptionsKey, PodmanOptions)
+}