Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement nerdctl compose exec -T #2507

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if noTTY, _ := flags.GetBool("no-TTY"); noTTY {
if noTTY, err := flags.GetBool("no-TTY"); err == nil && noTTY {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem necessary. When err != nil, noTTY is unlikely to be true.

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
Loading