Skip to content

feat: multi-space support#19

Merged
23prime merged 9 commits intomainfrom
feature/multi-space
Mar 8, 2026
Merged

feat: multi-space support#19
23prime merged 9 commits intomainfrom
feature/multi-space

Conversation

@23prime
Copy link
Owner

@23prime 23prime commented Mar 8, 2026

Checklist

  • Target branch is main
  • Status checks are passing

Summary

  • Add support for multiple Backlog spaces in a single bl installation
  • Old [auth] space_key config format is migrated automatically on first run

Reason for change

Users who belong to multiple Backlog spaces had to reconfigure credentials every time they switched spaces.

Changes

  • refactor(config): Replace single-space Config with current_space + spaces[]. Add current_space_key() helper that resolves BL_SPACE env var first, then falls back to current_space. Migrate old [auth] format transparently on load.
  • feat(auth): Add auth list, auth use <key>, auth logout [key], auth logout --all
  • feat: Add --space <SPACE_KEY> global flag for per-command space override
  • docs: Update user-guide with multi-space usage and uninstall instructions

Notes

LegacyAuthConfig and migrate() can be removed in a future version once the old config format is no longer in use.

23prime added 4 commits March 9, 2026 00:06
Replace single-space auth config with current_space + spaces list.
Add current_space_key() helper that resolves BL_SPACE env var first,
then falls back to current_space in config. Migrate old [auth] format
automatically on load.
- auth list: show all configured spaces with * on current
- auth use <key>: switch the current space
- auth logout: now takes optional space_key arg (defaults to current)
- auth logout --all: remove all spaces from keyring and delete config files
--space <SPACE_KEY> overrides the active space for a single command.
Internally sets BL_SPACE env var, which current_space_key() checks first.
Users can also export BL_SPACE directly for the same effect.
Document auth list, auth use, per-command --space flag, BL_SPACE env var,
logout with space key arg, logout --all, and new config file format.
Copilot AI review requested due to automatic review settings March 8, 2026 15:12
@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces multi-space authentication: config now tracks multiple spaces and a current space, CLI gains commands to list/use/logout per-space (and logout --all), login updates spaces/current, legacy configs are migrated on load, and client/auth flows resolve the active space via env or config.

Changes

Cohort / File(s) Summary
Configuration
src/config.rs
Replaced single auth with current_space: Option<String> and spaces: Vec<String>; renamed AuthConfigLegacyAuthConfig (skipped during serialization). Added current_space_key() resolver, remove_config_file(), and migration logic to import legacy space_key into new fields on load.
CLI & Dispatch
src/main.rs
Added global --space override to top-level CLI. Auth subcommands updated: Logout { space_key: Option<String>, all: bool }, plus new List and Use { space_key }. Early application of space override sets BL_SPACE env var; dispatch routes to new auth handlers.
Auth Commands
src/cmd/auth.rs
login persists spaces/current_space. logout signature changed to accept Option<&str>; added logout_all(), list(), and use_space() implementations. Status and credential removal updated to operate per-space; helper to prune spaces and adjust current_space added.
API Client
src/api/mod.rs
BacklogClient::from_config() now obtains API key via current_space_key() (env or config) instead of direct legacy auth access; base URL uses resolved space.
Secrets / Storage
src/secret.rs
Added remove_credentials_file() to delete credentials file when performing global logout or cleanup.
Documentation
docs/user-guide.md
Docs updated to describe multi-space workflow: list/use/targeting spaces, bl auth logout --all, updated uninstall guidance for Windows, and config format (current_space, spaces) with migration note.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as CLI (user)
  participant Config as Config
  participant Secret as Credentials Store
  participant API as Backlog API

  CLI->>Config: resolve current space (BL_SPACE or current_space_key())
  Config-->>CLI: return space_key
  CLI->>Secret: read/write credentials for space_key
  Secret-->>CLI: return API key / confirm deletion
  CLI->>API: initialize BacklogClient with API key and space in base_url
  API-->>CLI: respond to auth request (login/status)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 Hop, hop — spaces lined in a row,

I sniff each key where soft winds blow.
Old maps migrate, new paths unfurl,
Switch, list, or purge — give it a whirl!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.89% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: multi-space support' directly and clearly summarizes the main feature being added—support for managing multiple Backlog spaces in a single installation.
Description check ✅ Passed The description is directly related to the changeset, providing a clear summary of multi-space support including the motivation, specific changes to config/auth, new commands, flags, and documentation updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/multi-space
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feature/multi-space

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main.rs (1)

531-537: Consider adding mutual exclusivity between space_key and --all.

When both space_key and --all are provided, the current logic silently ignores space_key and runs logout_all(). This could confuse users who expect an error for conflicting arguments.

Option: Use clap's conflicts_with attribute
     /// Logout and remove stored credentials
     Logout {
         /// Space key to logout from (defaults to current space)
+        #[arg(conflicts_with = "all")]
         space_key: Option<String>,
         /// Logout from all spaces and remove all config files
         #[arg(long)]
         all: bool,
     },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main.rs` around lines 531 - 537, The Logout variant currently accepts
both space_key (Option<String>) and the flag all (bool) which can conflict;
update the clap configuration on the Logout variant to make these mutually
exclusive so the CLI returns an error when both are provided (e.g., use clap's
conflicts_with or similar on the all field or on space_key) so the code path
that calls logout_all() cannot silently ignore space_key; reference the Logout
enum and its fields space_key and all when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main.rs`:
- Around line 531-537: The Logout variant currently accepts both space_key
(Option<String>) and the flag all (bool) which can conflict; update the clap
configuration on the Logout variant to make these mutually exclusive so the CLI
returns an error when both are provided (e.g., use clap's conflicts_with or
similar on the all field or on space_key) so the code path that calls
logout_all() cannot silently ignore space_key; reference the Logout enum and its
fields space_key and all when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2ae3d997-6183-4e40-ac23-bfd431cb59ef

📥 Commits

Reviewing files that changed from the base of the PR and between 31ff0d1 and 0403db8.

📒 Files selected for processing (5)
  • docs/user-guide.md
  • src/api/mod.rs
  • src/cmd/auth.rs
  • src/config.rs
  • src/main.rs

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds multi-space support to the Backlog CLI by introducing a new config shape (current_space + spaces[]), space selection via BL_SPACE / --space, and new bl auth subcommands for managing multiple spaces.

Changes:

  • Refactor config loading to support multiple spaces and migrate legacy [auth] space_key on load.
  • Extend bl auth with list, use, and enhanced logout (per-space or --all), plus a global --space override.
  • Update API client initialization and user guide docs to reflect multi-space behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/main.rs Adds global --space flag and wires new auth subcommands/flags into CLI dispatch.
src/config.rs Replaces single-space auth metadata with current_space + spaces, adds current_space_key() and legacy migration logic + tests.
src/cmd/auth.rs Updates login/status to use the new config model and adds multi-space management commands (list, use, enhanced logout).
src/api/mod.rs Updates BacklogClient::from_config() to resolve the effective space via current_space_key().
docs/user-guide.md Documents multi-space workflows, updated logout semantics, and updated config format.

23prime added 5 commits March 9, 2026 00:22
Addresses review comment: "bl auth logout <space_key> --all is currently
accepted and the positional space_key is silently ignored"
Addresses review comment: "use_space() allocates a new String just to
check membership"
…ssage for missing space

Addresses review comment: "status() treats any error from
config::current_space_key() as 'not logged in'"
Addresses review comment: "logout_all() hardcodes the
~/.config/bl/{config.toml,credentials.toml} layout inline"
Extract remove_space_from_config() helper and test all removal cases:
current removed, non-current removed, last space removed.

Addresses review comment: "Multi-space behaviors were added, but this
module's tests currently cover only status_with/JSON building"
@23prime 23prime merged commit 6f85fb0 into main Mar 8, 2026
10 of 11 checks passed
@23prime 23prime deleted the feature/multi-space branch March 8, 2026 15:29
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