Skip to content

Commit

Permalink
Make --porcelain take precedence over config
Browse files Browse the repository at this point in the history
If humanize is set to true via the config, `--porcelain` is always
ignored. CLI will now take precedence.
  • Loading branch information
Hugo Osvaldo Barrera committed May 30, 2017
1 parent 342be9f commit 1063b8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,15 @@ def test_priority(runner):
])

assert '!!!' in result.output


def test_porcelain_precedence(runner, tmpdir):
"""Test that --humanize flag takes precedence over `porcelain` config"""

path = tmpdir.join('config')
path.write('humanize = true\n', 'a')

with patch('todoman.formatters.PorcelainFormatter') as mocked_formatter:
runner.invoke(cli, ['--porcelain', 'list'])

assert mocked_formatter.call_count is 1
6 changes: 3 additions & 3 deletions todoman/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ def cli(click_ctx, color, porcelain, humanize):
if humanize is None: # False means explicitly disabled
humanize = ctx.config['main']['humanize']

if humanize:
ctx.formatter_class = formatters.HumanizedFormatter
elif porcelain:
if porcelain:
ctx.formatter_class = formatters.PorcelainFormatter
elif humanize:
ctx.formatter_class = formatters.HumanizedFormatter
else:
ctx.formatter_class = formatters.DefaultFormatter

Expand Down

0 comments on commit 1063b8b

Please sign in to comment.