fix(stop): add --name flag to stop named contexts and instances#461
Open
AdeshDeshmukh wants to merge 1 commit into
Open
fix(stop): add --name flag to stop named contexts and instances#461AdeshDeshmukh wants to merge 1 commit into
AdeshDeshmukh wants to merge 1 commit into
Conversation
The stop command previously only supported stopping the current
context, with no way to target a specific context or instance by name.
This adds a --name flag that resolves the target via two-step lookup:
1. Try the name as a context name directly (handles login --name)
2. Fall back to scanning contexts by Instance field
(handles start --name, where context name is the server URL)
Fixes microcks#438
Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for stopping a Microcks instance by explicitly specifying a context or instance name via a new --name flag, including updated CLI help/examples.
Changes:
- Add
--nameflag tomicrocks stopwith updated usage examples. - Update stop logic to resolve a target context by context name, or fallback to searching by instance name.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+41
to
+46
| for _, c := range localConfig.Contexts { | ||
| if c.Instance == name { | ||
| ctxRef = &c | ||
| break | ||
| } | ||
| } |
Comment on lines
+47
to
+49
| if ctxRef == nil { | ||
| log.Fatalf("No context found for '%s'", name) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
microcks stopcommand only supports stopping the instance associated with the current context. There is no way to target a specific instance by name — even thoughmicrocks start --name <name>andmicrocks login --name <name>already allow users to create named contexts and instances.This asymmetry means that after starting multiple instances or logging into multiple servers, users have no direct way to stop a specific one without first switching context.
Root Cause
When a user runs
microcks start --name myinstance, the CLI stores the context with:http://localhost:8585(the server URL)myinstance(the user-given name)So a naive lookup by context name alone (
ResolveContext(myinstance)) fails — there is no context literally namedmyinstance. The existingResolveContextexpects the context's name field, not the Instance field.Solution
This PR adds a
--nameflag tomicrocks stopwith a two-tier fallback resolution:microcks login --name dev(stored asContext{Name: "dev"})microcks start --name myinstance(stored asContextRef{Name: "http://...", Instance: "myinstance"})If neither lookup succeeds, the user receives a clear error message.
When
--nameis omitted, behavior is 100% identical to the current code (uses the current context).Changes
cmd/stop.go— 29 insertions, 2 deletions:var name stringfor the flag variableExamplehelp text with usage patterns--nameflag onstopCmdVerification
go build ./...Example Usage
Fixes #438