diff --git a/main.py b/main.py index 5ffb883..886d55c 100755 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ from pkgmgr.config_init import config_init from pkgmgr.create_ink import create_ink from pkgmgr.deinstall_repos import deinstall_repos from pkgmgr.delete_repos import delete_repos -from pkgmgr.exec_git_command import exec_git_command +from pkgmgr.exec_proxy_command import exec_proxy_command from pkgmgr.filter_ignored import filter_ignored from pkgmgr.get_repo_identifier import get_repo_identifier from pkgmgr.get_selected_repos import get_selected_repos @@ -32,19 +32,29 @@ from pkgmgr.status_repos import status_repos from pkgmgr.update_repos import update_repos # Commands proxied by package-manager -GIT_DEFAULT_COMMANDS = [ - "pull", - "push", - "diff", - "add", - "show", - "checkout", - "clone", - "reset", - "revert", - "rebase", - "commit" -] +PROXY_COMMANDS = { + "git":[ + "pull", + "push", + "diff", + "add", + "show", + "checkout", + "clone", + "reset", + "revert", + "rebase", + "commit" + ], + "docker":[ + "start", + "stop" + ], + "docker compose":[ + "up", + "down" + ] +} class SortedSubParsersAction(argparse._SubParsersAction): def add_parser(self, name, **kwargs): @@ -162,25 +172,37 @@ For detailed help on each command, use: add_identifier_arguments(shell_parser) shell_parser.add_argument("-c", "--command", nargs=argparse.REMAINDER, dest="shell_command", help="The shell command (and its arguments) to execute in each repository",default=[]) - git_command_parsers = {} - # Proxies the default git commands - for git_command in GIT_DEFAULT_COMMANDS: - git_command_parsers[git_command] = subparsers.add_parser( - git_command, - help=f"Proxies 'git {git_command}' to one repository/repositories", - description=f"Executes 'git {git_command}' for the identified repos.\nTo recieve more help execute 'git {git_command} --help'", + proxy_command_parsers = {} + for command, subcommands in PROXY_COMMANDS.items(): + for subcommand in subcommands: + proxy_command_parsers[f"{command}_{subcommand}"] = subparsers.add_parser( + subcommand, + help=f"Proxies '{command} {subcommand}' to repository/ies", + description=f"Executes '{command} {subcommand}' for the identified repos.\nTo recieve more help execute '{command} {subcommand} --help'", formatter_class=argparse.RawTextHelpFormatter ) - add_identifier_arguments(git_command_parsers[git_command]) - if git_command in ["pull","clone"]: - git_command_parsers[git_command].add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg") - - + if subcommand in ["pull","clone"]: + proxy_command_parsers[f"{command}_{subcommand}"].add_argument("--no-verification", action="store_true", default=False, help="Disable verification via commit/gpg") + add_identifier_arguments(proxy_command_parsers[f"{command}_{subcommand}"]) + args = parser.parse_args() # All if args.command and not args.command in ["config","list","create"]: selected = get_selected_repos(args.all,all_repos_list,args.identifiers) + + for command, subcommands in PROXY_COMMANDS.items(): + for subcommand in subcommands: + if args.command == subcommand: + if args.command == "clone": + clone_repos(selected, repositories_base_dir, all_repos_list, args.preview, no_verification=args.no_verification) + elif args.command == "pull": + from pkgmgr.pull_with_verification import pull_with_verification + pull_with_verification(selected, repositories_base_dir, all_repos_list, args.extra_args, no_verification=args.no_verification, preview=args.preview) + else: + exec_proxy_command(command,selected, repositories_base_dir, all_repos_list, args.command, args.extra_args, args.preview) + exit(0) + # Dispatch commands. if args.command == "install": install_repos(selected,repositories_base_dir, BIN_DIR, all_repos_list, args.no_verification, preview=args.preview, quiet=args.quiet) @@ -195,14 +217,6 @@ For detailed help on each command, use: selected = get_selected_repos(True,all_repos_list,None) for identifier in args.identifiers: create_repo(identifier, config_merged, USER_CONFIG_PATH, BIN_DIR, remote=args.remote, preview=args.preview) - elif args.command in GIT_DEFAULT_COMMANDS: - if args.command == "clone": - clone_repos(selected, repositories_base_dir, all_repos_list, args.preview, no_verification=args.no_verification) - elif args.command == "pull": - from pkgmgr.pull_with_verification import pull_with_verification - pull_with_verification(selected, repositories_base_dir, all_repos_list, args.extra_args, no_verification=args.no_verification, preview=args.preview) - else: - exec_git_command(selected, repositories_base_dir, all_repos_list, args.command, args.extra_args, args.preview) elif args.command == "list": list_repositories(all_repos_list, repositories_base_dir, BIN_DIR, search_filter=args.search, status_filter=args.status) elif args.command == "deinstall": diff --git a/pkgmgr/exec_git_command.py b/pkgmgr/exec_proxy_command.py similarity index 63% rename from pkgmgr/exec_git_command.py rename to pkgmgr/exec_proxy_command.py index d8dcb8d..65b37f0 100644 --- a/pkgmgr/exec_git_command.py +++ b/pkgmgr/exec_proxy_command.py @@ -3,13 +3,13 @@ from pkgmgr.get_repo_identifier import get_repo_identifier from pkgmgr.get_repo_dir import get_repo_dir from pkgmgr.run_command import run_command -def exec_git_command(selected_repos, repositories_base_dir, all_repos, git_cmd, extra_args, preview=False): - """Execute a given git command with extra arguments for each repository.""" +def exec_proxy_command(proxy_prefix:str,selected_repos, repositories_base_dir, all_repos, proxy_command:str, extra_args, preview:bool): + """Execute a given proxy command with extra arguments for each repository.""" for repo in selected_repos: repo_identifier = get_repo_identifier(repo, all_repos) repo_dir = get_repo_dir(repositories_base_dir,repo) if os.path.exists(repo_dir): - full_cmd = f"git {git_cmd} {' '.join(extra_args)}" + full_cmd = f"{proxy_prefix} {proxy_command} {' '.join(extra_args)}" run_command(full_cmd, cwd=repo_dir, preview=preview) else: print(f"Repository directory '{repo_dir}' not found for {repo_identifier}.") \ No newline at end of file diff --git a/pkgmgr/status_repos.py b/pkgmgr/status_repos.py index 7ac49f4..24146d1 100644 --- a/pkgmgr/status_repos.py +++ b/pkgmgr/status_repos.py @@ -1,5 +1,5 @@ import sys -from .exec_git_command import exec_git_command +from .exec_proxy_command import exec_proxy_command from .run_command import run_command def status_repos(selected_repos, repositories_base_dir, all_repos, extra_args, list_only=False, system_status=False, preview=False): @@ -10,4 +10,4 @@ def status_repos(selected_repos, repositories_base_dir, all_repos, extra_args, l for repo in selected_repos: print(get_repo_identifier(repo, all_repos)) else: - exec_git_command(selected_repos, repositories_base_dir, all_repos, "status", extra_args, preview) \ No newline at end of file + exec_proxy_command('git',selected_repos, repositories_base_dir, all_repos, "status", extra_args, preview) \ No newline at end of file