diff mbox series

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

Message ID 20220701132328.v2.6.I79b8a2fc40f11af2ba8108f0f8166c574ae5ab47@changeid
State Superseded
Delegated to: Simon Glass
Headers show
Series patman: Small fixes plus remove --no-tree from checkpatch for linux | expand

Commit Message

Doug Anderson July 1, 2022, 8:24 p.m. UTC
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@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
---

Changes in v2:
- Make comment about parsing three times less nonsensical.

 tools/patman/main.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Simon Glass July 5, 2022, 9:59 a.m. UTC | #1
On Fri, 1 Jul 2022 at 14:24, Douglas Anderson <dianders@chromium.org> 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@chromium.org>
> Tested-by: Brian Norris <briannorris@chromium.org>
> ---
>
> Changes in v2:
> - Make comment about parsing three times less nonsensical.
>
>  tools/patman/main.py | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/tools/patman/main.py b/tools/patman/main.py
index feb26f22e46c..792124bb7555 100755
--- a/tools/patman/main.py
+++ b/tools/patman/main.py
@@ -108,14 +108,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)
-# Use parse_known_args() in case 'cmd' is omitted
+# Parse options several times:
+# - First to get the project.
+# - Second to handle defaults properly (which depends on project). This
+#   makes help display the right defaults.
+# - Finally after we have added an implicit command if necessary.
+#
+# Use parse_known_args() for the first two 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: