summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-05-29 12:12:06 +0100
committerChandan Singh <csingh43@bloomberg.net>2018-05-29 12:56:08 +0100
commit5eadfec95d48d59f82c284b4dcacf23f2d48351c (patch)
tree5c030d8a8ead023b99d50c4d0b1c272176434a0d
parentc0de75e2d44d9187181b4501887493c0057dedb0 (diff)
downloadbuildstream-chandan/add-argument-bst-pushreceive.tar.gz
_artifactcache/pushreceive.py: Add Click type for CLI argument 'repo'chandan/add-argument-bst-pushreceive
The CLI for `bst-artifact-receive` expects a `repo` argument, which is supposed to be a directory, but Click currently expects it to be just any string. This results in stack traces like the one below when the argument provided is not a directory: $ ~/.local/bin/bst-artifact-receive --pull-url http://foo foobaz Traceback (most recent call last): File "/root/.local/bin/bst-artifact-receive", line 8, in <module> sys.exit(receive_main()) ... File "/src/buildstream/buildstream/_artifactcache/pushreceive.py", line 581, in __init__ self.repo.open(None) GLib.Error: g-io-error-quark: /src/buildstream/43fref: opendir(/src/buildstream/foobaz): No such file or directory (1) Add types for this argument such that it throws better error messages when it receives bad arguments. With the Click types added, it will instead fail with messages like these: $ ~/.local/bin/bst-artifact-receive --pull-url http://foo foobaz Usage: bst-artifact-receive [OPTIONS] REPO Error: Invalid value for "repo": Directory "foobaz" does not exist. $ ~/.local/bin/bst-artifact-receive --pull-url http://foo setup.py Usage: bst-artifact-receive [OPTIONS] REPO Error: Invalid value for "repo": Directory "setup.py" is a file. Fixes #409.
-rw-r--r--buildstream/_artifactcache/pushreceive.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/buildstream/_artifactcache/pushreceive.py b/buildstream/_artifactcache/pushreceive.py
index 777065e18..ecedc6657 100644
--- a/buildstream/_artifactcache/pushreceive.py
+++ b/buildstream/_artifactcache/pushreceive.py
@@ -796,7 +796,7 @@ def push(repo, remote, branches, output):
@click.option('--debug', '-d', is_flag=True, default=False, help="Debug mode")
@click.option('--pull-url', type=str, required=True,
help="Clients who try to pull over SSH will be redirected here")
-@click.argument('repo')
+@click.argument('repo', type=click.Path(file_okay=False, dir_okay=True, writable=True, exists=True))
def receive_main(verbose, debug, pull_url, repo):
"""A BuildStream sister program for receiving artifacts send to a shared artifact cache
"""