fix(stop): add --name flag to stop named contexts and instances#461
fix(stop): add --name flag to stop named contexts and instances#461AdeshDeshmukh wants to merge 3 commits into
Conversation
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.
| for _, c := range localConfig.Contexts { | ||
| if c.Instance == name { | ||
| ctxRef = &c | ||
| break | ||
| } | ||
| } |
| if ctxRef == nil { | ||
| log.Fatalf("No context found for '%s'", name) | ||
| } |
912a936 to
3d52be8
Compare
|
Ptal at Copilot comments. If The resolution approach looks reasonable, but before merge I’d like targeted tests for:
I’d also like the precedence to be explicit and tested when a context name and an instance name collide. Right now context lookup wins, which is fine, but it should be intentional. |
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>
Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
Extract context resolution logic into resolveStopTarget() function with explicit precedence comment (context name checked first). Add 5 targeted tests: resolve by context name, instance name, not-found, collision (context wins), and empty name fallback. Signed-off-by: Adesh Deshmukh <adeshkd123@gmail.com>
3d52be8 to
7c960ac
Compare
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