container: Show default values in command help

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Use the default formatter on all the subparsers]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Veiko Aasa 2022-08-23 20:26:28 +03:00 committed by Sunil Mohan Adapa
parent 7f959ad304
commit 2f1feeadf1
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -257,19 +257,22 @@ systemd_version = None
def parse_arguments():
"""Return parsed command line arguments as dictionary."""
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
distributions = list(URLS.keys())
distribution = os.environ.get('DISTRIBUTION')
formatter_class = argparse.ArgumentDefaultsHelpFormatter
default_distribution = 'testing'
if distribution and distribution in distributions:
default_distribution = distribution
# Up
subparser = subparsers.add_parser('up', help='Bring up the container')
subparser = subparsers.add_parser('up', help='Bring up the container',
formatter_class=formatter_class)
subparser.add_argument(
'--distribution', choices=distributions, default=default_distribution,
help='Distribution of the image to download and setup')
@ -278,20 +281,23 @@ def parse_arguments():
# Print IP address
subparser = subparsers.add_parser(
'ip', help='Print the IP address of the container.')
'ip', help='Print the IP address of the container.',
formatter_class=formatter_class)
subparser.add_argument(
'--distribution', choices=distributions, default=default_distribution,
help='Distribution of the container to print IP address')
# ssh
subparser = subparsers.add_parser('ssh', help='SSH into the container')
subparser = subparsers.add_parser('ssh', help='SSH into the container',
formatter_class=formatter_class)
subparser.add_argument('--distribution', choices=distributions,
default=default_distribution,
help='Distribution of the container to SSH into')
# Run tests
subparser = subparsers.add_parser('run-tests',
help='Run tests in the container')
help='Run tests in the container',
formatter_class=formatter_class)
subparser.add_argument('--distribution', choices=distributions,
default=default_distribution,
help='Distribution of the container to run tests')
@ -300,21 +306,24 @@ def parse_arguments():
help='Additional arguments to pass to the pytest command')
# Stop
subparser = subparsers.add_parser('stop', help='Stop the container')
subparser = subparsers.add_parser('stop', help='Stop the container',
formatter_class=formatter_class)
subparser.add_argument('--distribution', choices=distributions,
default=default_distribution,
help='Distribution of the container to stop')
# Destroy
subparser = subparsers.add_parser('destroy',
help='Destroy the container image')
help='Destroy the container image',
formatter_class=formatter_class)
subparser.add_argument('--distribution', choices=distributions,
default=default_distribution,
help='Distribution of the image to delete')
# Update
subparser = subparsers.add_parser(
'update', help='Update the container image to the latest version')
'update', help='Update the container image to the latest version',
formatter_class=formatter_class)
subparser.add_argument('--distribution', choices=distributions,
default=default_distribution,
help='Distribution of the image to update')