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

Custom commands not listed #5673

Open
dunkmann00 opened this issue Jan 28, 2025 · 7 comments
Open

Custom commands not listed #5673

dunkmann00 opened this issue Jan 28, 2025 · 7 comments

Comments

@dunkmann00
Copy link

When I run the flask command by itself I get help output with all of my custom commands listed. But when I run flask --help I get the help output with only the built-in flask commands (routes, run, shell). I am using the FLASK_APP environment variable to load the app.

I would think I should get the same help output (showing my custom commands) whether or not I add the --help parameter?

Environment:

  • Python 3.12.2
  • Flask 3.1.0
@davidism
Copy link
Member

I don't think there's anything from Flask's side that can be done. The --app option is marked eager, and the eager --help option is added automatically by Click to the end of the param list. The problem is, Click orders param evaluation by command line presence and position first, then by list order. Since --help is the only option present on the command line in this case, it takes precedence. This could be something more general to report to Click, but I don't see how it can be addressed here.

@dunkmann00
Copy link
Author

I understand, thanks for that explanation @davidism.

@dunkmann00
Copy link
Author

@davidism I looked at the code that handles making a bare flask command correctly find the app and tried this slight change, which works. Not sure if there would be any unintended consequences I'm not thinking of, but I thought I'd share this to see if you think its a good idea/are open to it.

From cli.py L686-L694:

    def parse_args(self, ctx: click.Context, args: list[str]) -> list[str]:
-       if not args and self.no_args_is_help:
+       if (
+           (not args and self.no_args_is_help)
+           or (len(args) == 1 and args[0] in self.get_help_option_names(ctx))
+       ):
            # Attempt to load --env-file and --app early in case they
            # were given as env vars. Otherwise no_args_is_help will not
            # see commands from app.cli.
            _env_file_option.handle_parse_result(ctx, {}, [])
            _app_option.handle_parse_result(ctx, {}, [])


        return super().parse_args(ctx, args)

@davidism
Copy link
Member

Hmm, that probably won't work in all cases, but I think it's fine for this where people probably won't be overriding it. Can you create a PR?

@dunkmann00
Copy link
Author

@davidism No rush, but just wondering if you have had a chance to look at #5674?

@davidism
Copy link
Member

davidism commented Feb 3, 2025

Looks fine, but it will be a while before I have time to merge it and make a release.

@Burka111

This comment has been minimized.

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

No branches or pull requests

3 participants