From 39a80200524cd2291ec5f23b0e15016cf1d4ff3c Mon Sep 17 00:00:00 2001 From: Hugo Hornquist <hugo.hornquist@liu.se> Date: Sun, 22 Nov 2020 21:47:05 +0100 Subject: [PATCH] Add --dry-run. --- git-open | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/git-open b/git-open index f5c2408..5782da9 100755 --- a/git-open +++ b/git-open @@ -2,6 +2,8 @@ import sys import subprocess +import argparse + def popen(str): p = subprocess.Popen(str.split(" "), @@ -50,26 +52,27 @@ def main(args): out = popen("git remote") remotes = out.strip().split("\n") - remote = False - if len(args) == 2: - remote = sys.argv[1] + remote = args.remote - # TODO -n --no-act flag + do = open_remote + if args.dry_run: + do = lambda x: print(to_http(remote_url(x))) if not remotes: err("No remotes") - try: - open_remote(remote) - return - except Exception as e: - warn(str(e)) - warn("Giving up") - return + if remote: + try: + do(remote) + return + except Exception as e: + warn(str(e)) + warn("Giving up") + return for remote in remotes: try: - open_remote(remote) + do(remote) break except Exception as e: warn(str(e)) @@ -77,4 +80,9 @@ def main(args): err("All remotes failed") if __name__ == "__main__": - main(sys.argv) + parser = argparse.ArgumentParser(description='open git remotes in web browser') + parser.add_argument('-n', '--dry-run', action='store_true', dest='dry_run') + parser.add_argument('remote', action='store', nargs='?') + args = parser.parse_args() + main(args) + -- GitLab