8000 Avoid suggesting files in fish command completions. by bittrance · Pull Request #2114 · urfave/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Avoid suggesting files in fish command completions. #2114

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
Apr 27, 2025

Conversation

bittrance
Copy link
Contributor
@bittrance bittrance commented Apr 27, 2025

What type of PR is this?

  • bug

What this PR does / why we need it:

Ensure not to suggest paths in fish completions when subcommands are expected.

Which issue(s) this PR fixes:

Fixes #2113.

Testing

func main() {
	app := &cli.Command{
		Name:                  "mycli",
		Version:               "1.0.0",
		Usage:                 "Pure awesomeness.",
		EnableShellCompletion: true,
		Suggest:               true,
		Commands: []*cli.Command{
			{
				Name:  "level-up",
				Usage: "Become awesomer!",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:      "some-file",
						Usage:     "I take a file",
						TakesFile: true,
						Required:  true,
					},
				},
				Action: func(ctx context.Context, cmd *cli.Command) error {
					return nil
				},
			},
		},
	}
	if err := app.Run(context.Background(), os.Args); err != nil {
		log.Fatal(err)
	}
}

Release Notes

Fish completions for sub-commands no longer include files.

@bittrance bittrance requested a review from a team as a code owner April 27, 2025 11:09
@dearchap
Copy link
Contributor

@bittrance I'm not a fish expert but dont you want fish to suggested files for certain flags ?

@bittrance bittrance force-pushed the fish-completion-no-files branch from c7c3b7c to 74f70ee Compare April 27, 2025 19:40
@bittrance
Copy link
Contributor Author

@dearchap Oh, aboslutely. With this change there are two situations where you get file suggestions. Example code:

	app := &cli.Command{
		Name:                  "mycli",
		Version:               "1.0.0",
		Usage:                 "Pure awesomeness.",
                HideHelp:           true,
		EnableShellCompletion: true,
		Suggest:               true,
		Commands: []*cli.Command{
			{
				Name:  "awesomify",
				Usage: "Make awesomer!",
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:      "target-file",
						Required:  true,
						TakesFile: true,
					},
				},
				Action: func(ctx context.Context, cmd *cli.Command) error {
					return nil
				},
			},
		},
	}

Case 1: when there is nothing else to suggest:

$ mycli awesomify <tab>
fish-compl  go.mod  go.sum  main.go  mycli

Case 2: When using Flag TakesFile

$ mycli awesomify --target-file <tab>
fish-compl  go.mod  go.sum  main.go  mycli

As far as I can tell, the bash completions behave similarly?

@dearchap dearchap merged commit 6f37f6a into urfave:main Apr 27, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v3 fish completions include subcommands and files
2 participants
0