Last active
June 6, 2021 10:05
-
-
Save hmsjy2017/fc2a82fe3db999243be05dc710c6cf92 to your computer and use it in GitHub Desktop.
仿冒版git.py脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import clone | |
import init | |
def _init_subparsers(parent): | |
subparsers = parent.add_subparsers(title='sub commands') | |
parser_clone = subparsers.add_parser( | |
'clone', | |
help='Clone a repository into a new directory' | |
) | |
clone.init_parser(parser_clone) # add_argument() in module clone | |
parser_clone.set_defaults(func=clone.main) | |
parser_init = subparsers.add_parser( | |
'init', | |
help='Create an empty Git repository or reinitialize an existing one' | |
) | |
init.init_parser(parser_init) # add_argument() in module init | |
parser_init.set_defaults(func=init.main) | |
def _parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'-v', '--version', | |
action='version', | |
version='%(prog)s x.x.x', | |
) | |
_init_subparsers(parser) | |
return parser.parse_args() | |
if __name__ == '__main__': | |
args = _parse_args() | |
args.func(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment