Resolve name to oid in argparse
This commit is contained in:
parent
63dcbeb9e7
commit
671fa4b6b1
@ -96,9 +96,11 @@ def commit(message):
|
||||
|
||||
return oid
|
||||
|
||||
|
||||
def create_tag(name, oid):
|
||||
data.update_ref(f"refs/tags/{name}", oid)
|
||||
|
||||
|
||||
def checkout(oid):
|
||||
commit = get_commit(oid)
|
||||
read_tree(commit.tree)
|
||||
@ -126,5 +128,9 @@ def get_commit(oid):
|
||||
return Commit(tree=tree, parent=parent, message=message)
|
||||
|
||||
|
||||
def get_oid(name):
|
||||
return data.get_ref(name) or name
|
||||
|
||||
|
||||
def is_ignored(path):
|
||||
return ".ugit" in path.split("/")
|
||||
|
12
ugit/cli.py
12
ugit/cli.py
@ -19,6 +19,8 @@ def parse_args():
|
||||
commands = parser.add_subparsers(dest="command")
|
||||
commands.required = True
|
||||
|
||||
oid = base.get_oid
|
||||
|
||||
init_parser = commands.add_parser("init")
|
||||
init_parser.set_defaults(func=init)
|
||||
|
||||
@ -28,14 +30,14 @@ def parse_args():
|
||||
|
||||
cat_file_parser = commands.add_parser("cat-file")
|
||||
cat_file_parser.set_defaults(func=cat_file)
|
||||
cat_file_parser.add_argument("object")
|
||||
cat_file_parser.add_argument("object", type=oid)
|
||||
|
||||
write_tree_parser = commands.add_parser("write-tree")
|
||||
write_tree_parser.set_defaults(func=write_tree)
|
||||
|
||||
read_tree_parser = commands.add_parser("read-tree")
|
||||
read_tree_parser.set_defaults(func=read_tree)
|
||||
read_tree_parser.add_argument("tree")
|
||||
read_tree_parser.add_argument("tree", type=oid)
|
||||
|
||||
commit_parser = commands.add_parser("commit")
|
||||
commit_parser.set_defaults(func=commit)
|
||||
@ -43,16 +45,16 @@ def parse_args():
|
||||
|
||||
log_parser = commands.add_parser("log")
|
||||
log_parser.set_defaults(func=log)
|
||||
log_parser.add_argument("oid", nargs="?")
|
||||
log_parser.add_argument("oid", type=oid, nargs="?")
|
||||
|
||||
checkout_parser = commands.add_parser("checkout")
|
||||
checkout_parser.set_defaults(func=checkout)
|
||||
checkout_parser.add_argument("oid")
|
||||
checkout_parser.add_argument("oid", type=oid)
|
||||
|
||||
tag_parser = commands.add_parser("tag")
|
||||
tag_parser.set_defaults(func=tag)
|
||||
tag_parser.add_argument("name")
|
||||
tag_parser.add_argument("oid", nargs="?")
|
||||
tag_parser.add_argument("oid", type=oid, nargs="?")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user