Skip to content

feat(cli): add --profile flag to aw-cli (step 6 of #1399) - #151

Merged
ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/cli-profile
Aug 25, 2026
Merged

feat(cli): add --profile flag to aw-cli (step 6 of #1399)#151
ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:feat/cli-profile

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Summary

Step 6 of ActivityWatch/activitywatch#1399 — adds --profile NAME to aw-cli and drops the now-obsolete testing-based log filename filter.

What changed

aw_cli/__main__.py

  • main group gains --profile NAME option. --testing stays as a backward-compat alias for --profile testing.
  • Group callback sets os.environ["AW_PROFILE"] before any subcommand runs, so get_log_dir() / get_data_dir() / etc. automatically resolve to the correct profile directory (the isolation introduced in feat(dirs): profile isolation via AW_PROFILE appname suffix #149).
  • qt subcommand forwards --profile NAME to aw-qt (which gained profile support in aw-qt#128).
  • logs subcommand no longer passes testing down to find_oldest_log — the dir itself is already profile-specific.
  • directories subcommand needs no changes; it calls get_*_dir(None) which reads AW_PROFILE from the environment.

aw_cli/log.py

Tests

6 new tests in tests/test_cli_log.py covering the updated find_oldest_log behaviour. Full suite: 196 passed, 2 skipped.

Rollout context

This is step 6 in the rollout sequence. Steps 1–5 are merged:

Step Repo Status
1 aw-core #149 ✅ merged
3 aw-server #167 🔄 open, CI green
4 aw-client #118 🔄 open, CI green
5 aw-qt #128 ✅ merged 2026-08-25
6 aw-core (aw-cli) — this PR 🆕
7 aw-server-rust #652 🔄 open, CI green

The aw-cli qt subcommand spawns aw-qt, so step 6 was blocked on step 5 being merged first. That gate cleared today.

…ename filter

--profile NAME selects a named instance profile, resolving to the
activitywatch-<profile> platform dirs introduced in ActivityWatch#149. --testing
remains as an alias for --profile testing.

The qt subcommand now forwards --profile <name> to aw-qt (which gained
profile support in aw-qt#128). The logs subcommand relies on AW_PROFILE
being set in the environment (done by the group callback) so get_log_dir()
already returns the profile-specific directory; no filename-based filtering
is needed. find_oldest_log() drops the `testing` parameter accordingly.

Step 6 of ActivityWatch/activitywatch#1399.
@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds named-profile selection to aw-cli, keeps --testing as an alias, forwards profiles to aw-qt, and simplifies profile-isolated log selection.

  • Sets AW_PROFILE from the Click group callback for directory and log resolution.
  • Forwards the resolved profile across the aw-cli-to-aw-qt process boundary.
  • Removes filename-based testing-log filtering and adds focused log-selection tests.

Confidence Score: 4/5

The inherited-profile regression should be fixed before merging because ordinary aw-cli commands can silently operate on the default instance instead of the profile selected by their environment.

The new callback removes AW_PROFILE when no explicit option is present, changing directory lookup, log inspection, and the environment inherited by aw-qt from the selected profile to the default profile.

Files Needing Attention: aw_cli/main.py

Important Files Changed

Filename Overview
aw_cli/main.py Adds profile resolution and forwarding, but incorrectly clears an inherited AW_PROFILE when no profile option is supplied.
aw_cli/log.py Removes obsolete filename filtering and continues selecting the most recently modified log from the active profile directory.
tests/test_cli_log.py Covers missing, empty, single-file, modification-time, extension, and profile-like filename behavior for log selection.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[aw-cli options or inherited AW_PROFILE] --> B[Group callback]
    B --> C[AW_PROFILE environment]
    C --> D[directories]
    C --> E[logs]
    B --> F[qt]
    F --> G[aw-qt --profile NAME]
Loading

Reviews (1): Last reviewed commit: "feat(cli): add --profile flag to aw-cli,..." | Re-trigger Greptile

Comment thread aw_cli/__main__.py Outdated
Without this fix, running 'aw-cli <cmd>' with AW_PROFILE already set in the
environment would silently clear it, making directory/log lookups fall back
to the default profile instead of the inherited one.

Addresses Greptile's inherited-profile regression note on ActivityWatch#151.
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI is green (macOS, Ubuntu, Windows, lint). Greptile's P1 suggestion (guard os.environ["AW_PROFILE"] behind if active:) is already in the current code — the fix landed before the review ran. No changes needed. Ready for human review.

@ErikBjare
ErikBjare merged commit 16e493b into ActivityWatch:master Aug 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants