summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-09-17 16:02:42 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-09-17 20:17:11 +0200
commite0450694216e5e88df6f48aaa9f7adc91e3f23f3 (patch)
tree996dabb620b6bbe45f2e0e04b323d9e573c21639
parentab228fd3c3124d4fc4d927c91245072d8a0ec32d (diff)
downloadaur-e0450694216e5e88df6f48aaa9f7adc91e3f23f3.tar.gz
aur-e0450694216e5e88df6f48aaa9f7adc91e3f23f3.tar.xz
git-serve: Format usage text automatically
Remove the formatting of the usage text and add code to columnize it automatically instead. Also, add more strict tests for the usage output. These new tests ensure that the usage header is printed, commands are indented properly and no overly long lines are produced. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
-rwxr-xr-xgit-interface/git-serve.py26
-rwxr-xr-xgit-interface/test/t0002-serve.sh10
2 files changed, 27 insertions, 9 deletions
diff --git a/git-interface/git-serve.py b/git-interface/git-serve.py
index 38048c92..0187de9a 100755
--- a/git-interface/git-serve.py
+++ b/git-interface/git-serve.py
@@ -117,6 +117,14 @@ def warn(msg):
sys.stderr.write("warning: {:s}\n".format(msg))
+def usage(cmds):
+ sys.stderr.write("Commands:\n")
+ colwidth = max([len(cmd) for cmd in cmds.keys()]) + 4
+ for key in sorted(cmds):
+ sys.stderr.write(" " + key.ljust(colwidth) + cmds[key] + "\n")
+ exit(0)
+
+
user = os.environ.get('AUR_USER')
privileged = (os.environ.get('AUR_PRIVILEGED', '0') == '1')
ssh_cmd = os.environ.get('SSH_ORIGINAL_COMMAND')
@@ -187,13 +195,15 @@ elif action == 'restore':
os.environ["AUR_PKGBASE"] = pkgbase
os.execl(git_update_cmd, git_update_cmd, 'restore')
elif action == 'help':
- die("Commands:\n" +
- " help Show this help message and exit.\n" +
- " list-repos List all your repositories.\n" +
- " restore <name> Restore a deleted package base.\n" +
- " set-keywords <name> [...] Change package base keywords.\n" +
- " setup-repo <name> Create a repository (deprecated).\n" +
- " git-receive-pack Internal command used with Git.\n" +
- " git-upload-pack Internal command used with Git.")
+ cmds = {
+ "help": "Show this help message and exit.",
+ "list-repos": "List all your repositories.",
+ "restore <name>": "Restore a deleted package base.",
+ "set-keywords <name> [...]": "Change package base keywords.",
+ "setup-repo <name>": "Create a repository (deprecated).",
+ "git-receive-pack": "Internal command used with Git.",
+ "git-upload-pack": "Internal command used with Git.",
+ }
+ usage(cmds)
else:
die_with_help("invalid command: {:s}".format(action))
diff --git a/git-interface/test/t0002-serve.sh b/git-interface/test/t0002-serve.sh
index 52fdcd1e..ce8340e6 100755
--- a/git-interface/test/t0002-serve.sh
+++ b/git-interface/test/t0002-serve.sh
@@ -9,7 +9,15 @@ test_expect_success 'Test interactive shell.' '
'
test_expect_success 'Test help.' '
- SSH_ORIGINAL_COMMAND=help "$GIT_SERVE" 2>&1 | grep -q "^Commands:$"
+ SSH_ORIGINAL_COMMAND=help "$GIT_SERVE" 2>actual &&
+ save_IFS=$IFS
+ IFS=
+ while read -r line; do
+ echo $line | grep -q "^Commands:$" && continue
+ echo $line | grep -q "^ [a-z]" || return 1
+ [ ${#line} -le 80 ] || return 1
+ done <actual
+ IFS=$save_IFS
'
test_expect_success 'Test setup-repo and list-repos.' '