Skip to content

Instantly share code, notes, and snippets.

@ideasman42
Created July 6, 2021 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ideasman42/76ae54bba97cda4163b9e008189c48df to your computer and use it in GitHub Desktop.
Save ideasman42/76ae54bba97cda4163b9e008189c48df to your computer and use it in GitHub Desktop.
nerd-dictation diff
diff --git a/nerd-dictation b/nerd-dictation
index 3488618..6e688ab 100755
--- a/nerd-dictation
+++ b/nerd-dictation
@@ -1109,6 +1109,7 @@ This creates the directory used to store internal data, so other commands such a
output=args.output,
),
)
+ return subparse
def argparse_create_end(subparsers: argparse._SubParsersAction) -> None:
@@ -1129,6 +1130,8 @@ This ends dictation, causing the text to be typed in.
),
)
+ return subparse
+
def argparse_create_cancel(subparsers: argparse._SubParsersAction) -> None:
subparse = subparsers.add_parser(
@@ -1148,15 +1151,36 @@ This cancels dictation.
),
)
+ return subparse
+
def argparse_create() -> argparse.ArgumentParser:
- parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter)
+ parser = argparse.ArgumentParser(
+ description=__doc__,
+ formatter_class=argparse.RawTextHelpFormatter,
+ add_help=False,
+ )
subparsers = parser.add_subparsers()
- argparse_create_begin(subparsers)
- argparse_create_end(subparsers)
- argparse_create_cancel(subparsers)
+ subparsers_list = [
+ argparse_create_begin(subparsers),
+ argparse_create_end(subparsers),
+ argparse_create_cancel(subparsers),
+ ]
+
+ print_help_fn = parser.print_help
+ def print_help_wrapper():
+ print_help_fn()
+ for sub in subparsers_list:
+ print("\n")
+ print("Subcommand:")
+ sub.print_help()
+ print("\n")
+
+ parser.print_help = print_help_wrapper
+
+ parser.add_argument('-h', '--help', action='help')
return parser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment