mirror of
https://github.com/kp2pml30/git-third-party.git
synced 2026-02-16 23:54:41 +04:00
add --all
This commit is contained in:
parent
fed4821da3
commit
2732cbd9d0
1 changed files with 27 additions and 11 deletions
|
|
@ -107,18 +107,27 @@ def add(args: list[str]) -> None:
|
||||||
}
|
}
|
||||||
_update_at(name)
|
_update_at(name)
|
||||||
|
|
||||||
|
def _get_all_names() -> list[str]:
|
||||||
|
return list(config['repos'].keys())
|
||||||
|
|
||||||
|
def _get_names_from_paths(paths: list[str]) -> list[str]:
|
||||||
|
if len(paths) == 0:
|
||||||
|
raise GitThirdPartyException("excepted non-empty list of arguments")
|
||||||
|
if paths == ['--all']:
|
||||||
|
return _get_all_names()
|
||||||
|
return list(set(map(_get_path_rel_to_dir, paths)))
|
||||||
|
|
||||||
def update(args: list[str]) -> None:
|
def update(args: list[str]) -> None:
|
||||||
if len(args) != 1:
|
names = _get_names_from_paths(args)
|
||||||
print(f'Expected `{EXE_NAME} update <PATH>`, got {args}', file=sys.stderr)
|
for name in names:
|
||||||
exit(1)
|
_update_at(name)
|
||||||
name = _get_path_rel_to_dir(args[0])
|
|
||||||
_update_at(name)
|
|
||||||
|
|
||||||
def save(args: list[str]) -> None:
|
def save(args: list[str]) -> None:
|
||||||
if len(args) != 1:
|
names = _get_names_from_paths(args)
|
||||||
print(f'Expected `{EXE_NAME} save <PATH>`, got {args}', file=sys.stderr)
|
for name in names:
|
||||||
exit(1)
|
_save_at(name)
|
||||||
name = _get_path_rel_to_dir(args[0])
|
|
||||||
|
def _save_at(name: str) -> None:
|
||||||
_dirty_check(name)
|
_dirty_check(name)
|
||||||
conf = config['repos'][name]
|
conf = config['repos'][name]
|
||||||
patches_dir = _get_patches_dir(name)
|
patches_dir = _get_patches_dir(name)
|
||||||
|
|
@ -134,13 +143,20 @@ modes = {
|
||||||
"add": add,
|
"add": add,
|
||||||
"update": update,
|
"update": update,
|
||||||
"save": save,
|
"save": save,
|
||||||
|
"help": lambda x: show_help(*x, file=sys.stdout, exit_code=0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def show_help(*args, file=sys.stderr, exit_code=1):
|
||||||
|
if len(args) != 0:
|
||||||
|
print(f"help gets no arguments, got {args}", file=file)
|
||||||
|
exit_code = 1
|
||||||
|
print(f"USAGE: {EXE_NAME} {'|'.join(modes.keys())}", file=file)
|
||||||
|
exit(exit_code)
|
||||||
|
|
||||||
mode = sys.argv[1] if len(sys.argv) > 1 else '<not provided>'
|
mode = sys.argv[1] if len(sys.argv) > 1 else '<not provided>'
|
||||||
mode_handler = modes.get(mode, None)
|
mode_handler = modes.get(mode, None)
|
||||||
if mode_handler is None:
|
if mode_handler is None:
|
||||||
print(f"unknown mode {mode}, expected {EXE_NAME} {'|'.join(modes.keys())}", file=sys.stderr)
|
show_help()
|
||||||
exit(1)
|
|
||||||
try:
|
try:
|
||||||
mode_handler(sys.argv[2:])
|
mode_handler(sys.argv[2:])
|
||||||
except GitThirdPartyException as e:
|
except GitThirdPartyException as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue