Skip to content

Commit

Permalink
Enable settings the parser without bucket nor collection parameters.
Browse files Browse the repository at this point in the history
For xml2kinto and kinto2xml we need to define multiple bucket/collection couples.

r=@magopian
  • Loading branch information
Rémy HUBSCHER committed Mar 8, 2016
1 parent 4b62b8c commit afed3fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 10 additions & 6 deletions kinto_client/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def set_parser_server_options(parser=None,
default_auth=None,
default_bucket=None,
default_collection=None,
bucket=True,
collection=True,
**kwargs):

if parser is None:
Expand All @@ -50,13 +52,15 @@ def set_parser_server_options(parser=None,
help='BasicAuth token:my-secret',
type=str, default=default_auth, action=AuthAction)

parser.add_argument('-b', '--bucket',
help='Bucket name.',
type=str, default=default_bucket)
if bucket:
parser.add_argument('-b', '--bucket',
help='Bucket name.',
type=str, default=default_bucket)

parser.add_argument('-c', '--collection',
help='Collection name.',
type=str, default=default_collection)
if collection:
parser.add_argument('-c', '--collection',
help='Collection name.',
type=str, default=default_collection)

# Defaults
parser.add_argument('-v', '--verbose', action='store_const',
Expand Down
14 changes: 14 additions & 0 deletions kinto_client/tests/test_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ def test_set_parser_server_options_adds_arguments_on_existing_parser(self):
*ALL_PARAMETERS)
assert len(parser._actions) == 9

def test_set_parser_server_options_can_ignore_bucket_and_collection(self):
parser = cli_utils.set_parser_server_options(
bucket=None, collection=None)
parameters = [
['-h', '--help'],
['-s', '--server'],
['-a', '--auth'],
['-v', '--verbose'],
['-q', '--quiet'],
['-D', '--debug'],
]
self.assert_option_strings(parser, *parameters)
assert len(parser._actions) == 6

def test_can_change_default_values(self):
parser = cli_utils.set_parser_server_options(
default_server="https://firefox.settings.services.mozilla.com/",
Expand Down

0 comments on commit afed3fc

Please sign in to comment.