Skip to content

Commit

Permalink
Merge pull request #2507 from AkihiroSuda/compose-exec-T
Browse files Browse the repository at this point in the history
Implement `nerdctl compose exec -T`
  • Loading branch information
AkihiroSuda committed Sep 16, 2023
2 parents 017b0ea + 1605587 commit 5d07576
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 12 additions & 2 deletions cmd/nerdctl/compose_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,27 @@ func newComposeExecCommand() *cobra.Command {
}
composeExecCommand.Flags().SetInterspersed(false)

composeExecCommand.Flags().BoolP("tty", "t", true, "Allocate a pseudo-TTY")
composeExecCommand.Flags().BoolP("tty", "t", true, "Allocate a pseudo-TTY") // missing in Docker Compose v2?
composeExecCommand.Flags().BoolP("no-TTY", "T", false, "Disable pseudo-TTY allocation. By default nerdctl compose exec allocates a TTY.")
composeExecCommand.Flags().BoolP("interactive", "i", true, "Keep STDIN open even if not attached")
composeExecCommand.Flags().BoolP("detach", "d", false, "Detached mode: Run containers in the background")
composeExecCommand.Flags().StringP("workdir", "w", "", "Working directory inside the container")
// env needs to be StringArray, not StringSlice, to prevent "FOO=foo1,foo2" from being split to {"FOO=foo1", "foo2"}
composeExecCommand.Flags().StringArrayP("env", "e", nil, "Set environment variables")
// TODO: no-TTY flag
composeExecCommand.Flags().Bool("privileged", false, "Give extended privileges to the command")
composeExecCommand.Flags().StringP("user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
composeExecCommand.Flags().Int("index", 1, "index of the container if the service has multiple instances.")

composeExecCommand.PreRunE = func(cmd *cobra.Command, args []string) error {
flags := cmd.Flags()
if noTTY, _ := flags.GetBool("no-TTY"); noTTY {
if err := flags.Set("tty", "false"); err != nil {
return err
}
}
return nil
}

return composeExecCommand
}

Expand Down
3 changes: 1 addition & 2 deletions docs/command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1427,11 +1427,10 @@ Flags:
- :whale: `-i, --interactive`: Keep STDIN open even if not attached (default true)
- :whale: `--privileged`: Give extended privileges to the command
- :whale: `-t, --tty`: Allocate a pseudo-TTY
- :whale: `-T, --no-TTY`: Disable pseudo-TTY allocation. By default nerdctl compose exec allocates a TTY.
- :whale: `-u, --user`: Username or UID (format: `<name|uid>[:<group|gid>]`)
- :whale: `-w, --workdir`: Working directory inside the container

Unimplemented `docker-compose exec` (V2) flags: `-T, --no-TTY`

### :whale: nerdctl compose down

Remove containers and associated resources
Expand Down

0 comments on commit 5d07576

Please sign in to comment.