子命令分派
要使用子命令分派生成git风格的命令行界面,您可以
只需要创建子命令函数,主命令将
为您自动生成。defroar():"""Usage: cat-sounds roar"""print('ROAR!')defmeow():"""Usage: cat-sounds meow"""print('Meow!')
这将自动生成命令cat sounds并提供以下帮助
消息:Usage:
cat-sounds [--help] [--version] [--log-level | --debug | --verbose]
[...]
Options:
-h, --help Display this help message and exit.
-V, --version Display the version and exit.
-d, --debug Set the log level to DEBUG.
-v, --verbose Set the log level to INFO.
--log-level Set the log level to one of DEBUG, INFO, WARN, or ERROR.
'cat-sounds help -a' lists all available subcommands.
See 'cat-sounds help ' for more information on a specific command.