| 31 | ) |
| 32 | |
| 33 | func ExecCommand() *cobra.Command { |
| 34 | var cmd = &cobra.Command{ |
| 35 | Use: "exec [flags] CONTAINER COMMAND [ARG...]", |
| 36 | Args: cobra.MinimumNArgs(2), |
| 37 | Short: "Run a command in a running container", |
| 38 | RunE: execAction, |
| 39 | ValidArgsFunction: execShellComplete, |
| 40 | SilenceUsage: true, |
| 41 | SilenceErrors: true, |
| 42 | } |
| 43 | cmd.Flags().SetInterspersed(false) |
| 44 | |
| 45 | cmd.Flags().BoolP("tty", "t", false, "Allocate a pseudo-TTY") |
| 46 | cmd.Flags().BoolP("interactive", "i", false, "Keep STDIN open even if not attached") |
| 47 | cmd.Flags().BoolP("detach", "d", false, "Detached mode: run command in the background") |
| 48 | cmd.Flags().StringP("workdir", "w", "", "Working directory inside the container") |
| 49 | // env needs to be StringArray, not StringSlice, to prevent "FOO=foo1,foo2" from being split to {"FOO=foo1", "foo2"} |
| 50 | cmd.Flags().StringArrayP("env", "e", nil, "Set environment variables") |
| 51 | // env-file is defined as StringSlice, not StringArray, to allow specifying "--env-file=FILE1,FILE2" (compatible with Podman) |
| 52 | cmd.Flags().StringSlice("env-file", nil, "Set environment variables from file") |
| 53 | cmd.Flags().Bool("privileged", false, "Give extended privileges to the command") |
| 54 | cmd.Flags().StringP("user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])") |
| 55 | return cmd |
| 56 | } |
| 57 | |
| 58 | func execOptions(cmd *cobra.Command) (types.ContainerExecOptions, error) { |
| 59 | // We do not check if we have a terminal here, as container.Exec calling console.Current will ensure that |