Commit dc38947e authored by Cyril Roelandt's avatar Cyril Roelandt
Browse files

CLI: make --frontend/--backend optional in some conditions.

If there is only one frontend available, it is automatically selected,
and '--frontend' is not required. The same is true for the '--backend'
option.
parent 39308b80
......@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
Based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## [Unreleased]
### Changed
- cli: --frontend/--backend is optional when there is only one
frontend/backend available
## [0.7] - 2019-04-28
### Added
- upt.Archive: add a "filename" attribute
......
......@@ -110,33 +110,45 @@ class TestUtils(unittest.TestCase):
class TestParser(unittest.TestCase):
def setUp(self):
self.parser = upt.upt.create_parser(['pypi'], ['guix'])
def test_package_single_frontend(self):
parser = upt.upt.create_parser(['pypi'], ['guix', 'nix'])
args = 'package -b guix requests'.split()
parser.parse_args(args)
def test_package_single_backend(self):
parser = upt.upt.create_parser(['cpan', 'pypi'], ['guix'])
args = 'package -f pypi requests'.split()
parser.parse_args(args)
def test_package_missing_frontend(self):
parser = upt.upt.create_parser(['cpan', 'pypi'], ['guix', 'nix'])
args = 'package -b guix requests'.split()
with self.assertRaises(SystemExit):
self.parser.parse_args(args)
parser.parse_args(args)
def test_package_missing_backend(self):
parser = upt.upt.create_parser(['cpan', 'pypi'], ['guix', 'nix'])
args = 'package -f pypi requests'.split()
with self.assertRaises(SystemExit):
self.parser.parse_args(args)
parser.parse_args(args)
def test_package_missing_frontend_and_backend(self):
parser = upt.upt.create_parser(['cpan', 'pypi'], ['guix', 'nix'])
args = 'package requests'.split()
with self.assertRaises(SystemExit):
self.parser.parse_args(args)
parser.parse_args(args)
def test_package_missing_package(self):
parser = upt.upt.create_parser(['cpan', 'pypi'], ['guix', 'nix'])
args = 'package -f pypi -b guix'.split()
with self.assertRaises(SystemExit):
self.parser.parse_args(args)
parser.parse_args(args)
def test_package_exclusive_logging_options(self):
parser = upt.upt.create_parser(['cpan', 'pypi'], ['guix', 'nix'])
args = 'package -f pypi -b guix --debug --quiet requests'.split()
with self.assertRaises(SystemExit):
self.parser.parse_args(args)
parser.parse_args(args)
class TestCommandLine(unittest.TestCase):
......
......@@ -208,11 +208,15 @@ def create_parser(frontends, backends):
parser_package = subparsers.add_parser('package',
help='Package a piece of software')
required_args = parser_package.add_argument_group('Required arguments')
required_args.add_argument('-f', '--frontend', required=True,
required_args.add_argument('-f', '--frontend',
required=len(frontends) > 1,
choices=frontends,
default=frontends[0] if frontends else None,
help='Frontend to use')
required_args.add_argument('-b', '--backend', required=True,
required_args.add_argument('-b', '--backend',
required=len(backends) > 1,
choices=backends,
default=backends[0] if backends else None,
help='Backend to use')
logger_group = parser_package.add_mutually_exclusive_group()
logger_group.add_argument('--debug', action='store_const',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment