[PATCH 6/6] patman: Take project defaults into account for --help

Brian Norris briannorris at chromium.org
Fri Jul 1 00:15:53 CEST 2022


On Thu, Jun 30, 2022 at 02:08:09PM -0700, Doug Anderson wrote:
> I'd like it so that when you do "patman send --help" and you're using
> Linux that it show it the proper defaults for Linux.
> 
> Signed-off-by: Douglas Anderson <dianders at chromium.org>
> ---
> 
>  tools/patman/main.py | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/patman/main.py b/tools/patman/main.py
> index 1ee44feab192..a0b0ad3bad9d 100755
> --- a/tools/patman/main.py
> +++ b/tools/patman/main.py
> @@ -109,14 +109,19 @@ status.add_argument('-d', '--dest-branch', type=str,
>  status.add_argument('-f', '--force', action=BooleanOptionalAction,
>                      help='Force overwriting an existing branch')
>  
> -# Parse options twice: first to get the project and second to handle
> -# defaults properly (which depends on project)
> +# Parse options several times:
> +# - first to get the project and second to handle defaults properly (which
> +#   depends on project).
> +# - second to handle --help after we've accounted for project defaults.

The previous bullet has a "second", and so does this one. Are those
different meanings, or are we counting wrong?

This might be a good place to say that this multiple passes on argparse
is very confusing to me. That's not to say that you need to explain it
for me, but just to say I'm probably not the best reviewer on this one.

Brian

> +# - finally after we have added an implicit command if necessary.
> +#
>  # Use parse_known_args() in case 'cmd' is omitted
> +argv = [arg for arg in sys.argv[1:] if arg not in ('-h', '--help')]
> +args, _ = parser.parse_known_args(argv)
>  argv = sys.argv[1:]
> -args, rest = parser.parse_known_args(argv)
>  if hasattr(args, 'project'):
>      settings.Setup(gitutil, parser, args.project, '')
> -    args, rest = parser.parse_known_args(argv)
> +args, rest = parser.parse_known_args(argv)
>  
>  # If we have a command, it is safe to parse all arguments
>  if args.cmd:
> -- 
> 2.37.0.rc0.161.g10f37bed90-goog
> 


More information about the U-Boot mailing list