Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 147:ed35f3c9e2b5
Add also a "help" subcommand to "treesum".
It can show the global general help or the help message for a given
subcommand.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 03 Jan 2025 16:51:26 +0100 |
| parents | 7d8df8311e3b |
| children | 17d6e760143f |
comparison
equal
deleted
inserted
replaced
| 146:7d8df8311e3b | 147:ed35f3c9e2b5 |
|---|---|
| 117 help="Alias for \"generate\"", | 117 help="Alias for \"generate\"", |
| 118 description="Generate checksums for directory trees. " | 118 description="Generate checksums for directory trees. " |
| 119 "This is an alias to \"generate\".") | 119 "This is an alias to \"generate\".") |
| 120 _populate_generate_arguments(genparser2) | 120 _populate_generate_arguments(genparser2) |
| 121 | 121 |
| 122 subparsers.add_parser( | 122 hparser = subparsers.add_parser( |
| 123 "help", | |
| 124 help="Show this help message or a subcommand's help and exit", | |
| 125 description="Show this help message or a subcommand's help and exit.") | |
| 126 hparser.add_argument("help_command", nargs='?', metavar="COMMAND") | |
| 127 | |
| 128 vparser = subparsers.add_parser( | |
| 123 "version", | 129 "version", |
| 124 help="Show the program's version number and exit", | 130 help="Show the program's version number and exit", |
| 125 description="Show the program's version number and exit.") | 131 description="Show the program's version number and exit.") |
| 126 | 132 |
| 127 # Parse leniently to just check for "version" | 133 # Parse leniently to just check for "version" and/or help |
| 128 opts, _dummy = parser.parse_known_args(args=argv) | 134 opts, _dummy = parser.parse_known_args(args=argv) |
| 129 | 135 |
| 130 if opts.subcommand == "version": | 136 if opts.subcommand == "version": |
| 131 print("%s (rv:%s)" % (__version__, __revision__), | 137 print("%s (rv:%s)" % (__version__, __revision__), |
| 132 file=sys.stdout) | 138 file=sys.stdout) |
| 139 sys.exit(0) | |
| 140 if opts.subcommand == "help": | |
| 141 if not opts.help_command: | |
| 142 parser.print_help() | |
| 143 else: | |
| 144 if opts.help_command == "generate": | |
| 145 genparser.print_help() | |
| 146 elif opts.help_command == "gen": | |
| 147 genparser2.print_help() | |
| 148 elif opts.help_command == "version": | |
| 149 vparser.print_help() | |
| 150 elif opts.help_command == "help": | |
| 151 hparser.print_help() | |
| 152 else: | |
| 153 parser.print_help() | |
| 133 sys.exit(0) | 154 sys.exit(0) |
| 134 | 155 |
| 135 # Reparse strictly | 156 # Reparse strictly |
| 136 opts = parser.parse_args(args=argv) | 157 opts = parser.parse_args(args=argv) |
| 137 | 158 |
