Skip to content

feat: add --context flag for temporary config profile switching#235

Merged
JannikSt merged 2 commits intomainfrom
feat/context-flag
Dec 4, 2025
Merged

feat: add --context flag for temporary config profile switching#235
JannikSt merged 2 commits intomainfrom
feat/context-flag

Conversation

@JannikSt
Copy link
Copy Markdown
Member

@JannikSt JannikSt commented Dec 3, 2025

Summary

  • Adds --context/-c global flag to temporarily use a different config profile for a single command
  • Similar to kubectl --context - allows switching between users/environments without running prime config use

Usage

# Instead of:
prime config use user1
prime sandbox create ...
prime config use user2
prime sandbox create ...

# You can now do:
prime --context user1 sandbox create ...
prime --context user2 sandbox create ...

# Or with short flag:
prime -c production pods list

Implementation

  • Added --context option to main app callback
  • Sets PRIME_CONTEXT env var which Config checks on init
  • Added persist=False option to load_environment() for in-memory-only loading

Test plan

  • prime --context production config view shows production config
  • prime config view after still shows original config (not persisted)
  • prime --context nonexistent ... shows helpful error with available contexts
  • All existing tests pass

Closes #91


Note

Adds a global --context/-c flag that temporarily switches the config environment for a single command via PRIME_CONTEXT, backed by Config.load_environment(..., persist=False).

  • CLI:
    • Add global --context/-c option in prime_cli/main.py to use a specific config environment per command.
    • Validates context (except production) against Config.list_environments() and prints available contexts on error.
    • Sets PRIME_CONTEXT so subcommands inherit the selected environment.
  • Config:
    • Check PRIME_CONTEXT on init in core/config.py and load_environment(context, persist=False) for in-memory override.
    • Extend load_environment(name, persist=True|False) to support non-persistent loading for production and saved environments, including URL normalization and selective field updates.

Written by Cursor Bugbot for commit 580d47c. This will update automatically on new commits. Configure here.

Adds a --context/-c global flag to temporarily use a different config
profile for a single command, similar to kubectl --context.

Usage:
  prime --context user1 sandbox create ...
  prime -c production pods list

The context is only applied for that command and does not persist.

Closes #91
Comment thread packages/prime/src/prime_cli/core/config.py Outdated
Comment thread packages/prime/src/prime_cli/core/config.py
Copy link
Copy Markdown
Contributor

@pokgak pokgak left a comment

Choose a reason for hiding this comment

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

this one a bit confusing because --context need to be explicitly before any subcommands like prime --context local sandbox list and not prime sandbox list --context=local. works but ideally we should be able to put it anywhere after prime.

not a big issue tho so approved.

raise typer.Exit()

if context:
import os
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move this to top file?

@JannikSt JannikSt merged commit 8fd4503 into main Dec 4, 2025
11 checks passed
@JannikSt JannikSt deleted the feat/context-flag branch December 4, 2025 01:18
@JannikSt JannikSt mentioned this pull request Dec 4, 2025
4 tasks
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.

config: support --context for switching between config profiles

2 participants