Skip to content

[completion] Fix shell completion when specifying --config flag #2632

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

Merged
merged 1 commit into from
Jun 18, 2025
Merged
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
17 changes: 16 additions & 1 deletion internal/boxcli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package boxcli
import (
"fmt"
"log/slog"
"os"
"slices"
"sort"
"strings"
Expand Down Expand Up @@ -82,8 +83,22 @@ func runCmd(defaults runFlagDefaults) *cobra.Command {
}

func listScripts(cmd *cobra.Command, flags runCmdFlags) []string {
path := flags.config.path

// Special code path for shell completion.
// Landau: I'm not entirely sure why:
// * Flags need to be parsed again
// * cmd.Flag("config") contains the correct value, but flags.config.path is empty
// Give my low confidence, I'm making this a very narrow code path.
if path == "" && slices.Contains(os.Args, "__complete") {
_ = cmd.ParseFlags(os.Args)
if flag := cmd.Flag("config"); flag != nil && flag.Value != nil {
path = flag.Value.String()
}
}

devboxOpts := &devopt.Opts{
Dir: flags.config.path,
Dir: path,
Environment: flags.config.environment,
Stderr: cmd.ErrOrStderr(),
IgnoreWarnings: true,
Expand Down
Loading