mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-02 05:37:51 +00:00
* --remote, --url and --identity are now anchored to podman command. Subcommands should no longer have issues * TraverseChildren now set to V1 expectations * Latest flag now has helper function. Now has consistent usage. * IsRemote() uses cobra parser to determin if --remote is given * Moved validation functions from parser pkg to validate pkg * Fixes #6598 Fixes #6704 Signed-off-by: Jhon Honce <jhonce@redhat.com> <MH: Fixed import issues> Signed-off-by: Matt Heon <matthew.heon@pm.me>
96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
package containers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"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/libpod/define"
|
|
"github.com/containers/libpod/v2/pkg/domain/entities"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
var (
|
|
waitDescription = `Block until one or more containers stop and then print their exit codes.
|
|
`
|
|
waitCommand = &cobra.Command{
|
|
Use: "wait [flags] CONTAINER [CONTAINER...]",
|
|
Short: "Block on one or more containers",
|
|
Long: waitDescription,
|
|
RunE: wait,
|
|
Args: validate.IDOrLatestArgs,
|
|
Example: `podman wait --interval 5000 ctrID
|
|
podman wait ctrID1 ctrID2`,
|
|
}
|
|
|
|
containerWaitCommand = &cobra.Command{
|
|
Use: waitCommand.Use,
|
|
Short: waitCommand.Short,
|
|
Long: waitCommand.Long,
|
|
RunE: waitCommand.RunE,
|
|
Args: validate.IDOrLatestArgs,
|
|
Example: `podman container wait --interval 5000 ctrID
|
|
podman container wait ctrID1 ctrID2`,
|
|
}
|
|
)
|
|
|
|
var (
|
|
waitOptions = entities.WaitOptions{}
|
|
waitCondition string
|
|
)
|
|
|
|
func waitFlags(flags *pflag.FlagSet) {
|
|
flags.DurationVarP(&waitOptions.Interval, "interval", "i", time.Duration(250), "Milliseconds to wait before polling for completion")
|
|
flags.StringVar(&waitCondition, "condition", "stopped", "Condition to wait on")
|
|
}
|
|
|
|
func init() {
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
|
Command: waitCommand,
|
|
})
|
|
waitFlags(waitCommand.Flags())
|
|
validate.AddLatestFlag(waitCommand, &waitOptions.Latest)
|
|
|
|
registry.Commands = append(registry.Commands, registry.CliCommand{
|
|
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
|
|
Command: containerWaitCommand,
|
|
Parent: containerCmd,
|
|
})
|
|
waitFlags(containerWaitCommand.Flags())
|
|
validate.AddLatestFlag(containerWaitCommand, &waitOptions.Latest)
|
|
|
|
}
|
|
|
|
func wait(cmd *cobra.Command, args []string) error {
|
|
var (
|
|
err error
|
|
errs utils.OutputErrors
|
|
)
|
|
if waitOptions.Interval == 0 {
|
|
return errors.New("interval must be greater then 0")
|
|
}
|
|
|
|
waitOptions.Condition, err = define.StringToContainerStatus(waitCondition)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
responses, err := registry.ContainerEngine().ContainerWait(context.Background(), args, waitOptions)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, r := range responses {
|
|
if r.Error == nil {
|
|
fmt.Println(r.ExitCode)
|
|
} else {
|
|
errs = append(errs, r.Error)
|
|
}
|
|
}
|
|
return errs.PrintErrors()
|
|
}
|