Skip to content

Commit

Permalink
Adds option to recognize mutual options -R, -r
Browse files Browse the repository at this point in the history
  • Loading branch information
derphilipp committed Jan 8, 2016
1 parent f353b5f commit a544bdf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 5 additions & 2 deletions pwgrep/command_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ class CommandParser(object):
def __init__(self, args):
self._parser = argparse.ArgumentParser(prog='pwgrep', add_help=False)

self._parser.add_argument(
recursion_group = self._parser.add_mutually_exclusive_group()

recursion_group.add_argument(
'-R', '--dereference-recursive',
action='store_true',
help=command_parser_text.DEREFERENCE_RECURSIVE
)
self._parser.add_argument(
recursion_group.add_argument(
'-r', '--recursive',
action='store_true',
help=command_parser_text.RECURSIVE)

self._parser.add_argument(
'-h', '--no-filename',
action='store_true',
Expand Down
12 changes: 11 additions & 1 deletion tests/system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,10 @@ def test_color_auto_color():
helper_test_match(SIMPLEDIR, '--color=auto Zen *', expected_stdout, '', 0)


# Wrong options
def test_color_wrong_option():
# argparse exits with exit code 2 ('incorrect usage')
expected_stderr = """usage: pwgrep [-R] [-r] [-h] [-i] [-v] [-o] [--color [COLOR]] [--version]
expected_stderr = """usage: pwgrep [-R | -r] [-h] [-i] [-v] [-o] [--color [COLOR]] [--version]
[--help]
PATTERN [PATH [PATH ...]]
pwgrep: error: argument --color: unrecognized is not a valid color option
Expand All @@ -175,6 +176,15 @@ def test_color_wrong_option():
'', expected_stderr, 2)


def test_regex_wrong_option():
expected_stderr = """usage: pwgrep [-R | -r] [-h] [-i] [-v] [-o] [--color [COLOR]] [--version]
[--help]
PATTERN [PATH [PATH ...]]
pwgrep: error: argument -r/--recursive: not allowed with argument -R/--dereference-recursive
"""
helper_test_match(SIMPLEDIR, '-R -r Hello .', '', expected_stderr, 2)


# stdin
def test_stdin_l():
stdin = b"""Hello
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ passenv =
*
usedevelop = true

commands =
py.test {posargs}

[testenv:coverage]
basepython = python2.7
Expand Down

0 comments on commit a544bdf

Please sign in to comment.