From 293bf930a11ce2eb42ed2fbf31958b0b90da6fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Wed, 15 Aug 2018 13:32:17 +0200 Subject: [PATCH] Better multi-call support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also supports calling by secondary argument (kind-of busybox stylekind-of). Drop support for multicall setuptools wrapper – when installed using setuptools, the user should call explicit function instead. --- dzonegit.py | 28 ++++++++++++++++++---------- setup.py | 1 - 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/dzonegit.py b/dzonegit.py index 2df0a28..b5c0d3d 100644 --- a/dzonegit.py +++ b/dzonegit.py @@ -495,17 +495,25 @@ def post_receive(stdin=sys.stdin): subprocess.run(cmd) +def get_action(argv=sys.argv): + name = Path(argv[0]).name + if "pre-commit" in name: + return pre_commit + if "update" in name: + return update + if "pre-receive" in name: + return pre_receive + if "post-receive" in name: + return post_receive + + def main(): - name = Path(sys.argv[0]).name - print(name) - if name == "pre-commit": - pre_commit() - elif name == "update": - update() - elif name == "pre-receive": - pre_receive() - elif name == "post-receive": - post_receive() + action = get_action() + if action is None and len(sys.argv) > 1: + sys.argv.pop(0) + action = get_action() + if action: + action() else: sys.exit("No valid command found") diff --git a/setup.py b/setup.py index 7a5e0c1..502376d 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,6 @@ setup( tests_require=["pytest"], entry_points={ "console_scripts": [ - "dzonegit = dzonegit:main", "dzonegit-pre-commit = dzonegit:pre_commit", "dzonegit-pre-receive = dzonegit:pre_receive", "dzonegit-post-receive = dzonegit:post_receive",