Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for the length of watson log #436

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -238,6 +242,7 @@ log_current = false
pager = true
report_current = false
reverse_log = true
log_length = 3
```

## Application folder
Expand Down
31 changes: 31 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down