Skip to content

feat: add --org flag to all relevant CLI commands#341

Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1774368282-add-org-flag-shell-open
Open

feat: add --org flag to all relevant CLI commands#341
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1774368282-add-org-flag-shell-open

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 24, 2026

Summary

Adds --org / -o flag to all relevant CLI commands so users can override the active org for workspace resolution without needing to run brev set {org} first. This prevents the common "instance not found" error when a user's active org doesn't match the org containing their workspace.

Commands updated:

  • brev shell, brev open (initial scope)
  • brev stop, brev copy, brev exec, brev port-forward
  • brev create (gpucreate), brev reset, brev recreate
  • brev ollama, brev workspacegroups

New shared utilities (pkg/cmd/util/):

  • ResolveOrgFromFlag — resolves org from flag or falls back to active org
  • GetUserWorkspaceByNameOrIDErrInOrg — workspace lookup in a specific org
  • ResolveWorkspaceOrNodeInOrg — workspace-or-node lookup in a specific org
  • GetAnyWorkspaceByIDOrNameInOrgErr — any-workspace (admin) lookup in a specific org

All commands with the flag also register tab completion via GetOrgsNameCompletionHandler, except ollama (hidden command) and workspacegroups (stub command). Commands whose store interfaces embed completions.CompletionStore already had GetOrganizations; GPUCreateStore, OllamaStore, and WorkspaceGroupsStore had GetOrganizations added explicitly.

notebook.go was updated to pass "" (default org) for the new RunPortforward parameter since it doesn't expose --org itself.

Updates since last revision

  • Fixed CI: added GetOrganizations method to MockGPUCreateStore in gpucreate_test.go so the mock satisfies the updated GPUCreateStore interface.
  • All 9 CI checks now pass (build, lint, fmt, tests, CodeQL, release-test, cli-output-compatibility).

Review & Testing Checklist for Human

  • Manual test with two orgs: Run commands like brev stop <instance> --org <non-active-org>, brev shell <instance> --org <non-active-org>, brev create ... --org <non-active-org> to confirm correct workspace resolution across all updated commands.
  • Verify default behavior unchanged: Run the same commands without --org and confirm they still use the active org as before.
  • FindExternalNode still uses GetActiveOrganizationOrDefault() — when --org is passed, workspace lookup uses the resolved org, but the external node fallback in ResolveWorkspaceOrNodeInOrg still searches the active org. Decide if this inconsistency is acceptable for shell, open, copy, and port-forward.
  • stop admin pathstopWorkspace falls back to GetAnyWorkspaceByIDOrNameInOrgErr for admins. Verify this works correctly when --org is passed and the workspace belongs to another user in that org.
  • gpucreate removed nil guardnewCreateContext previously checked if org == nil after GetActiveOrganizationOrDefault(). Now ResolveOrgFromFlag returns an error instead of nil. Confirm the error message ("no orgs exist") is acceptable.

Notes

  • ResolveOrgFromFlag duplicates the same logic as getOrgForRunLs in ls.go. A follow-up could consolidate ls.go to use the shared utility.
  • No new unit tests were added for the shared utilities (ResolveOrgFromFlag, GetUserWorkspaceByNameOrIDErrInOrg). These would benefit from coverage in a follow-up.
  • ollama and workspacegroups register the --org flag but do not register tab completion for it (unlike the other commands). This is intentional since they are hidden/stub commands.

Link to Devin session: https://app.devin.ai/sessions/b9480e7c87b747e5b1d681faa65eddcb
Requested by: @theFong

Add --org flag support to brev shell and brev open commands, following
the existing pattern from brev start and brev ls. When provided, the
--org flag overrides the active org for workspace resolution, preventing
'instance not found' errors when users haven't set their org context.

Changes:
- Add ResolveOrgFromFlag utility in pkg/cmd/util for shared org resolution
- Add GetUserWorkspaceByNameOrIDErrInOrg for org-specific workspace lookup
- Add ResolveWorkspaceOrNodeInOrg for org-specific workspace/node resolution
- Add --org/-o flag with tab completion to shell command
- Add --org/-o flag with tab completion to open command

Co-Authored-By: Alec Fong <alecsanf@usc.edu>
@devin-ai-integration devin-ai-integration bot requested a review from a team as a code owner March 24, 2026 16:11
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 0% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.63%. Comparing base (88dc335) to head (6420e8a).
⚠️ Report is 26 commits behind head on main.

Files with missing lines Patch % Lines
pkg/cmd/util/util.go 0.00% 25 Missing ⚠️
pkg/cmd/open/open.go 0.00% 15 Missing ⚠️
pkg/cmd/shell/shell.go 0.00% 15 Missing ⚠️
pkg/cmd/util/externalnode.go 0.00% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #341      +/-   ##
==========================================
+ Coverage   14.77%   17.63%   +2.85%     
==========================================
  Files         127      140      +13     
  Lines       16977    18528    +1551     
==========================================
+ Hits         2508     3267     +759     
- Misses      14182    14902     +720     
- Partials      287      359      +72     
Flag Coverage Δ
Linux 17.63% <0.00%> (+2.85%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add --org / -o flag to: stop, copy, exec, portforward, gpucreate,
reset, recreate, ollama, workspacegroups commands.

Also adds GetAnyWorkspaceByIDOrNameInOrgErr utility for org-specific
workspace lookups and updates notebook.go caller for new RunPortforward
signature.

Co-Authored-By: Alec Fong <alecsanf@usc.edu>
@devin-ai-integration devin-ai-integration bot changed the title feat: add --org flag to shell and open commands feat: add --org flag to all relevant CLI commands Mar 24, 2026
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.

1 participant