mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-13 02:57:53 +00:00
With the advent of Podman 2.0.0 we crossed the magical barrier of go modules. While we were able to continue importing all packages inside of the project, the project could not be vendored anymore from the outside. Move the go module to new major version and change all imports to `github.com/containers/libpod/v2`. The renaming of the imports was done via `gomove` [1]. [1] https://github.com/KSubedi/gomove Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
package containers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/containers/libpod/v2/cmd/podman/registry"
|
|
"github.com/containers/libpod/v2/cmd/podman/utils"
|
|
"github.com/containers/libpod/v2/cmd/podman/validate"
|
|
"github.com/containers/libpod/v2/pkg/domain/entities"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
var (
|
|
initDescription = `Initialize one or more containers, creating the OCI spec and mounts for inspection. Container names or IDs can be used.`
|
|
|
|
initCommand = &cobra.Command{
|
|
Use: "init [flags] CONTAINER [CONTAINER...]",
|
|
Short: "Initialize one or more containers",
|
|
Long: initDescription,
|
|
RunE: initContainer,
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
return validate.CheckAllLatestAndCIDFile(cmd, args, false, false)
|
|
},
|
|
Example: `podman init --latest
|
|
podman init 3c45ef19d893
|
|
podman init test1`,
|
|
}
|
|
|
|
containerInitCommand = &cobra.Command{
|
|
Use: initCommand.Use,
|
|
Short: initCommand.Short,
|
|
Long: initCommand.Long,
|
|
RunE: initCommand.RunE,
|
|
Args: initCommand.Args,
|
|
Example: `podman container init --latest
|
|
podman container init 3c45ef19d893
|
|
podman container init test1`,
|
|
}
|
|
)
|
|
|
|
var (
|
|
initOptions entities.ContainerInitOptions
|
|
)
|
|
|
|
func initFlags(flags *pflag.FlagSet) {
|
|
flags.BoolVarP(&initOptions.All, "all", "a", false, "Initialize all containers")
|
|
}
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
|
Command: initCommand,
|
|
})
|
|
flags := initCommand.Flags()
|
|
initFlags(flags)
|
|
validate.AddLatestFlag(initCommand, &initOptions.Latest)
|
|
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
|
Parent: containerCmd,
|
|
Command: containerInitCommand,
|
|
})
|
|
containerInitFlags := containerInitCommand.Flags()
|
|
initFlags(containerInitFlags)
|
|
validate.AddLatestFlag(containerInitCommand, &initOptions.Latest)
|
|
}
|
|
|
|
func initContainer(cmd *cobra.Command, args []string) error {
|
|
var errs utils.OutputErrors
|
|
report, err := registry.ContainerEngine().ContainerInit(registry.GetContext(), args, initOptions)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, r := range report {
|
|
if r.Err == nil {
|
|
fmt.Println(r.Id)
|
|
} else {
|
|
errs = append(errs, r.Err)
|
|
}
|
|
}
|
|
return errs.PrintErrors()
|
|
}
|