From b8fe52f72afc0b7973f3d207f6aebb0f427246d5 Mon Sep 17 00:00:00 2001
From: Tristan Van Berkom <tristan.vanberkom@codethink.co.uk>
Date: Mon, 10 Jul 2017 22:21:25 +0900
Subject: [PATCH] bst-artifact-receive: Use click instead of argparse

This will help with man page generation.
---
 buildstream/_artifactcache/pushreceive.py | 26 +++++++++++------------
 setup.py                                  |  2 +-
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/buildstream/_artifactcache/pushreceive.py b/buildstream/_artifactcache/pushreceive.py
index a7f78710ec..8204003808 100644
--- a/buildstream/_artifactcache/pushreceive.py
+++ b/buildstream/_artifactcache/pushreceive.py
@@ -19,8 +19,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-from argparse import ArgumentParser
-from enum import Enum
+import click
 import logging
 import os
 import struct
@@ -30,6 +29,7 @@ import tempfile
 import shutil
 import tarfile
 import signal
+from enum import Enum
 from urllib.parse import urlparse
 
 from .. import _signals
@@ -582,22 +582,20 @@ def push(repo, remote, branch, output):
             terminate_push()
 
 
-def receive_main():
-    aparser = ArgumentParser(description='Receive pushed ostree objects')
-    aparser.add_argument('--repo', help='repository path')
-    aparser.add_argument('-v', '--verbose', action='store_true',
-                         help='enable verbose output')
-    aparser.add_argument('--debug', action='store_true',
-                         help='enable debugging output')
-    args = aparser.parse_args()
-
+@click.command(short_help="Receive pushed artifacts over ssh")
+@click.option('--repo', help="Repository path to add artifacts to")
+@click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode")
+@click.option('--debug', '-d', is_flag=True, default=False, help="Debug mode")
+def receive_main(repo, verbose, debug):
+    """A BuildStream sister program for receiving artifacts send to a shared artifact cache
+    """
     loglevel = logging.WARNING
-    if args.verbose:
+    if verbose:
         loglevel = logging.INFO
-    if args.debug:
+    if debug:
         loglevel = logging.DEBUG
     logging.basicConfig(format='%(module)s: %(levelname)s: %(message)s',
                         level=loglevel, stream=sys.stderr)
 
-    receiver = OSTreeReceiver(args.repo)
+    receiver = OSTreeReceiver(repo)
     return receiver.run()
diff --git a/setup.py b/setup.py
index b680985746..f362739c18 100755
--- a/setup.py
+++ b/setup.py
@@ -119,8 +119,8 @@ setup(name='BuildStream',
       ],
       entry_points='''
       [console_scripts]
-      bst=buildstream._frontend:cli
       bst-artifact-receive=buildstream._artifactcache:receive_main
+      bst=buildstream._frontend:cli
       ''',
       setup_requires=['pytest-runner', 'setuptools_scm'],
       tests_require=['pep8',
-- 
GitLab