Skip to content

Conversation

@onasser1
Copy link
Contributor

Related #19867

@onasser1 onasser1 requested review from a team as code owners October 25, 2025 15:34
@bunnyshell
Copy link

bunnyshell bot commented Oct 25, 2025

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@onasser1
Copy link
Contributor Author

/component cli

# Switch Argo CD context
argocd context cd.argoproj.io
argocd context switch cd.argoproj.io
Copy link
Member

Choose a reason for hiding this comment

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

how about argocd context use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I'm not wrong, the switch command does exactly the same as use command, do you mean to change the name of the command from switch to be use?
If this is not what you mean, can you tell me the difference between them?

Copy link
Contributor

Choose a reason for hiding this comment

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

@onasser1 I believe @nitishfy is suggesting to use the term use instead of switch just like kubectl command

Copy link
Contributor Author

@onasser1 onasser1 Nov 4, 2025

Choose a reason for hiding this comment

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

@ppapapetrou76 I added use as an alias for switch command in the latest commit.
Do you think I should replace switch completely with use? or keep them together with alias?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think argocd context use cd.argoproj.io would be a more intuitive and consistent choice here.
The word “use” aligns with common CLI patterns like kubectl config use-context and clearly conveys the action of setting the active context.
You could still keep switch as an alias, but use would be better as the primary example.

err := deleteContext(args[0], clientOpts.ConfigPath)
errors.CheckError(err)
return
func NewContextListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func NewContextListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
// NewContextListCommand lists the contexts
func NewContextListCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think we should to stick to the function comments format in app and login (i.e. https://github.com/argoproj/argo-cd/blob/master/cmd/argocd/commands/app.go#L124)
or apply your change and make the comment more meaningful (Anyway I see that the usage of that commands make it clear anyway) but I'd wait for your answer

Copy link
Member

@nitishfy nitishfy left a comment

Choose a reason for hiding this comment

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

Thank you for the PR. The code looks good to me. Here are few suggestions:

  1. Please write comments in the code wherever required, eg. in the code for switch command.
  2. Write unit tests for the utility functions.
  3. You'll be required to run codegen to update the docs too.

@nitishfy nitishfy changed the title feat: Add context login CLI sub command feat(cli): add argocd context subcommands Oct 27, 2025
return false
}

func (l *LocalConfig) GetContext(ctxName string) (*ContextRef, error) {
Copy link
Member

Choose a reason for hiding this comment

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

please write unit tests.

Co-authored-by: Nitish Kumar <[email protected]>
Signed-off-by: Omar Nasser <[email protected]>
@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 48.10127% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.28%. Comparing base (b260143) to head (22ec297).
⚠️ Report is 70 commits behind head on master.

Files with missing lines Patch % Lines
cmd/argocd/commands/context.go 50.00% 34 Missing and 4 partials ⚠️
util/localconfig/localconfig.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #25077      +/-   ##
==========================================
+ Coverage   60.83%   62.28%   +1.44%     
==========================================
  Files         350      351       +1     
  Lines       60430    49273   -11157     
==========================================
- Hits        36762    30688    -6074     
+ Misses      20754    15663    -5091     
- Partials     2914     2922       +8     

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

@onasser1 onasser1 requested a review from nitishfy October 29, 2025 11:53
@onasser1 onasser1 force-pushed the feat/add-context-login-subcommand branch from 3580699 to 9c1e965 Compare October 29, 2025 14:00
Signed-off-by: Omar Nasser <[email protected]>
Signed-off-by: Omar Nasser <[email protected]>

Provide use command as alias for switch

Signed-off-by: Omar Nasser <[email protected]>
Comment on lines +67 to +73
func NewContextSwitchCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
command := &cobra.Command{
Use: "switch",
Aliases: []string{"use"},
Short: "Switch Argo CD Context",
Example: ` # Switch Argo CD Context
argocd context switch cd.argoproj.io`,
Copy link
Contributor

@Mangaal Mangaal Nov 12, 2025

Choose a reason for hiding this comment

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

Suggested change
func NewContextSwitchCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
command := &cobra.Command{
Use: "switch",
Aliases: []string{"use"},
Short: "Switch Argo CD Context",
Example: ` # Switch Argo CD Context
argocd context switch cd.argoproj.io`,
func NewContextUseCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
command := &cobra.Command{
Use: "use",
Aliases: []string{"switch"},
Short: "Set Argo CD Context",
Example: ` # Set Argo CD context
argocd context use cd.argoproj.io`,

Copy link
Contributor

@Mangaal Mangaal left a comment

Choose a reason for hiding this comment

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

I have added a few comments and suggestions, feel free to resolve them if you agree with the changes.

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.

5 participants