diff --git a/CHANGELOG.md b/CHANGELOG.md index 06cec57c..d4f5c1ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- The restart command now accepts the `--gap/--no-gap` options. +- The restart command now accepts the `--gap/--no-gap` options. (#437) +- The default log length can now be controlled via the configuration option + `log_length`. (#436) ## [2.0.1] - 2021-05-10 diff --git a/docs/user-guide/configuration.md b/docs/user-guide/configuration.md index be163b8f..a6aac5d3 100644 --- a/docs/user-guide/configuration.md +++ b/docs/user-guide/configuration.md @@ -116,6 +116,10 @@ If `true`, the output of the `log` command will include the currently running frame (if any) by default. The option can be overridden on the command line with the `-c/-C` resp. `--current/--no-current` flags. +#### `options.log_length` (default: `7`) + +The number of previous days to show when running `watson log`. + #### `options.pager` (default: `true`) If `true`, the output of the `log` and `report` command will be @@ -238,6 +242,7 @@ log_current = false pager = true report_current = false reverse_log = true +log_length = 3 ``` ## Application folder diff --git a/tests/test_cli.py b/tests/test_cli.py index 2a1b3a52..c3cdffb2 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -150,6 +150,37 @@ def test_log_invalid_date(runner, watson, test_dt): assert result.exit_code != 0 +def test_log_length_config(runner, watson, mocker): + # Add three days worth of data + start_dt = arrow.now() + end_dt = start_dt + timedelta(hours=1) + runner.invoke( + cli.add, + ['-f', start_dt, '-t', end_dt, 'project-name'], + obj=watson) + runner.invoke( + cli.add, + ['-f', start_dt - timedelta(days=1), + '-t', end_dt - timedelta(days=1), + 'project-name'], + obj=watson) + runner.invoke( + cli.add, + ['-f', start_dt - timedelta(days=2), + '-t', end_dt - timedelta(days=2), + 'project-name'], + obj=watson) + + # Use newlines to test how many days are displayed in the log output + watson.config.set('options', 'log_length', 1) + result = runner.invoke(cli.log, obj=watson) + assert result.output.count('\n') == 5 + + watson.config.set('options', 'log_length', 2) + result = runner.invoke(cli.log, obj=watson) + assert result.output.count('\n') == 8 + + # watson report @pytest.mark.parametrize('test_dt,expected', VALID_DATES_DATA) diff --git a/watson/cli.py b/watson/cli.py index 22bd369b..90d2aaf2 100644 --- a/watson/cli.py +++ b/watson/cli.py @@ -914,7 +914,7 @@ def aggregate(ctx, watson, current, from_, to, projects, tags, output_format, @click.option('-r/-R', '--reverse/--no-reverse', 'reverse', default=None, help="(Don't) reverse the order of the days in output.") @click.option('-f', '--from', 'from_', type=DateTime, - default=arrow.now().shift(days=-7), + default=None, help="The date from when the log should start. Defaults " "to seven days ago.") @click.option('-t', '--to', type=DateTime, default=arrow.now(), @@ -1041,6 +1041,9 @@ def log(watson, current, reverse, from_, to, projects, tags, ignore_projects, 02cb269,2014-04-16 09:53,2014-04-16 12:43,apollo11,wheels 1070ddb,2014-04-16 13:48,2014-04-16 16:17,voyager1,"antenna, sensors" """ # noqa + if from_ is None: + log_length = watson.config.getint('options', 'log_length', 7) + from_ = arrow.now().shift(days=-log_length) for start_time in (_ for _ in [day, week, month, luna, year, all] if _ is not None): from_ = start_time