comparison cutils/treesum.py @ 148:17d6e760143f

Optimize help / usage output for the global options. Use an argparser group and let disable automatic "-h/--help" arguments.
author Franz Glasner <fzglas.hg@dom66.de>
date Fri, 03 Jan 2025 17:04:29 +0100
parents ed35f3c9e2b5
children f717854be1de
comparison
equal deleted inserted replaced
147:ed35f3c9e2b5 148:17d6e760143f
88 gp.add_argument( 88 gp.add_argument(
89 "directories", nargs="*", metavar="DIRECTORY") 89 "directories", nargs="*", metavar="DIRECTORY")
90 90
91 parser = argparse.ArgumentParser( 91 parser = argparse.ArgumentParser(
92 description="Generate and verify checksums for directory trees.", 92 description="Generate and verify checksums for directory trees.",
93 fromfile_prefix_chars='@') 93 fromfile_prefix_chars='@',
94 94 add_help=False)
95
96 #
95 # Global options for all sub-commands 97 # Global options for all sub-commands
96 parser.add_argument( 98 #
99 gparser = parser.add_argument_group(title="Global Options")
100 gparser.add_argument(
97 "-v", "--version", action="version", 101 "-v", "--version", action="version",
98 version="%s (rv:%s)" % (__version__, __revision__)) 102 version="%s (rv:%s)" % (__version__, __revision__),
99 103 help="Show program's version number and exit")
104 gparser.add_argument(
105 "-h", "--help", action="help",
106 help="Show this help message and exit")
107
108 #
109 # Subcommands
110 #
100 subparsers = parser.add_subparsers( 111 subparsers = parser.add_subparsers(
101 dest="subcommand", 112 dest="subcommand",
102 title="Commands", 113 title="Commands",
103 description="This tool uses subcommands. " 114 description="This tool uses subcommands. "
104 "To see detailed help for a specific subcommand use " 115 "To see detailed help for a specific subcommand use "
105 "the -h/--help option after the subcommand name. " 116 "the -h/--help option after the subcommand name. "
106 "A short list of valid commands are listed below:", 117 "A list of valid commands and their short descriptions "
118 "is listed below:",
107 metavar="COMMAND") 119 metavar="COMMAND")
108 120
109 genparser = subparsers.add_parser( 121 genparser = subparsers.add_parser(
110 "generate", 122 "generate",
111 help="Generate checksums for directory trees.", 123 help="Generate checksums for directory trees.",