diff --git a/manage.py b/manage.py index c04f730..8d81142 100755 --- a/manage.py +++ b/manage.py @@ -300,28 +300,37 @@ def main(): print("\nUsing socket " + env['socket'] + ".") - print("\nChoose action:") - print("[1/S] Setup project") - print("[2/U] Update project") - print("[3/B] Backup project") action = '' + if len(sys.argv) > 1: + action = sys.argv[1] + else: + print("\nChoose action:") + print("[1/S] Setup project") + print("[2/U] Update project") + print("[3/B] Backup project") + while action == '': action = input("Action: ") + projects = os.listdir("projects") print(f"\nProjects list: {projects}") - - target_projects = input("Target compose project(s), space separated, leave empty to target all: ") + if len(sys.argv) > 2: + target_projects = sys.argv[2] + else: + target_projects = input("Target compose project(s), space separated, leave empty to target all: ") if target_projects == '': target_projects = projects else: - target_projects = target_projects.split(' ') + target_projects = re.split(' ?, ?| ', target_projects.strip()) + print(f"Target projects: {target_projects}") - match action: - case '1' | 'S': + + match action.casefold(): + case '1' | 's' | 'setup': setNftables() for project in target_projects: @@ -332,7 +341,7 @@ def main(): print(e, file=sys.stderr) print(f"Failed to setup project {project}.", file=sys.stderr) - case '2' | 'U': + case '2' | 'u' | 'update': for project in target_projects: try: print() @@ -341,7 +350,7 @@ def main(): print(e, file=sys.stderr) print(f"Failed to update project {project}.", file=sys.stderr) - case '3' | 'B': + case '3' | 'b' | 'backup': print() if not os.path.exists(env['borg_repo']): print(f"Creating borg repository {env['borg_repo']}.")