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 option to control the order of the days in the log output #369

Merged
merged 4 commits into from
Jun 18, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add --reverse/--no-reverse flag to log
joelostblom committed Jun 18, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit a2deba9a016381cdfdf38e98a85487b7212f8a9d
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Improve Arrow 0.15.0 support after changes in `arrow.get()` behavior (#296)
- Watson now suggests correct command if users make small typo (#318)
- Log output order can now be controlled via the `--reverse/--no-reverse` flag
and the `reverse_log` configuration option (#369)

### Changed

3 changes: 2 additions & 1 deletion docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
@@ -133,7 +133,8 @@ command line with the `-c/-C` resp. `--current/--no-current` flags.

If `true`, the output of the `log` command will reverse the order of the days
to display the latest day's entries on top and the oldest day's entries at the
bottom.
bottom. The option can be overridden on the command line with the `-r/-R` resp.
`--reverse/--no-reverse` flags.

#### `options.stop_on_start` (default: `false`)

11 changes: 8 additions & 3 deletions watson/cli.py
Original file line number Diff line number Diff line change
@@ -853,6 +853,8 @@ def aggregate(ctx, watson, current, from_, to, projects, tags, output_format,
@cli.command()
@click.option('-c/-C', '--current/--no-current', 'current', default=None,
help="(Don't) include currently running frame in output.")
@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),
help="The date from when the log should start. Defaults "
@@ -908,8 +910,8 @@ def aggregate(ctx, watson, current, from_, to, projects, tags, output_format,
help="(Don't) view output through a pager.")
@click.pass_obj
@catch_watson_error
def log(watson, current, from_, to, projects, tags, year, month, week, day,
luna, all, output_format, pager):
def log(watson, current, reverse, from_, to, projects, tags, year, month, week,
day, luna, all, output_format, pager):
"""
Display each recorded session during the given timespan.

@@ -986,6 +988,9 @@ def log(watson, current, from_, to, projects, tags, year, month, week, day,
watson.frames.add(cur['project'], cur['start'], arrow.utcnow(),
cur['tags'], id="current")

if reverse is None:
reverse = watson.config.getboolean('options', 'reverse_log', True)

span = watson.frames.span(from_, to)
filtered_frames = watson.frames.filter(
projects=projects or None, tags=tags or None, span=span
@@ -1002,7 +1007,7 @@ def log(watson, current, from_, to, projects, tags, year, month, week, day,
frames_by_day = sorted_groupby(
filtered_frames,
operator.attrgetter('day'),
reverse=watson.config.getboolean('options', 'reverse_log', True)
reverse=reverse
)

lines = []