Add validators schema and code templates
This commit is contained in:
74
src/templates/python.handlebars
Normal file
74
src/templates/python.handlebars
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Auto-generated CLI argument parser for {{spec.name}}."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
__version__ = "{{spec.version}}"
|
||||||
|
|
||||||
|
|
||||||
|
def create_parser():
|
||||||
|
"""Create and configure the argument parser."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog="{{spec.name}}",
|
||||||
|
description="{{spec.description}}"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--version",
|
||||||
|
action="version",
|
||||||
|
version="%(prog)s " + __version__
|
||||||
|
)
|
||||||
|
|
||||||
|
{{#each spec.globalOptions}}
|
||||||
|
{{> option}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
{{#each spec.commands}}
|
||||||
|
{{> command}}
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
{{#*inline "option"}}
|
||||||
|
{{#if (eq type "boolean")}}
|
||||||
|
parser.add_argument(
|
||||||
|
"{{name}}",
|
||||||
|
{{#if short}}-{{short}}, {{/if}}
|
||||||
|
action="store_true",
|
||||||
|
help="{{escape description}}"
|
||||||
|
)
|
||||||
|
{{else}}
|
||||||
|
parser.add_argument(
|
||||||
|
"{{name}}",
|
||||||
|
{{#if short}}-{{short}}, {{/if}}
|
||||||
|
type={{toPythonType type}},
|
||||||
|
help="{{escape description}}"
|
||||||
|
)
|
||||||
|
{{/if}}
|
||||||
|
{{/inline}}
|
||||||
|
|
||||||
|
|
||||||
|
{{#*inline "command"}}
|
||||||
|
{{#if subcommands}}
|
||||||
|
subparsers = parser.add_subparsers(title="commands", dest="command")
|
||||||
|
{{#each subcommands}}
|
||||||
|
{{name}}_parser = subparsers.add_parser("{{name}}", help="{{escape description}}")
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
{{/inline}}
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main entry point."""
|
||||||
|
parser = create_parser()
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.command:
|
||||||
|
print("Command:", args.command)
|
||||||
|
else:
|
||||||
|
parser.print_help()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user