Skip to content

fix(stop): add --name flag to stop named contexts and instances#461

Open
AdeshDeshmukh wants to merge 1 commit into
microcks:masterfrom
AdeshDeshmukh:fix/stop-name-flag
Open

fix(stop): add --name flag to stop named contexts and instances#461
AdeshDeshmukh wants to merge 1 commit into
microcks:masterfrom
AdeshDeshmukh:fix/stop-name-flag

Conversation

@AdeshDeshmukh

Copy link
Copy Markdown

Problem

The microcks stop command only supports stopping the instance associated with the current context. There is no way to target a specific instance by name — even though microcks start --name <name> and microcks 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:

  • Context name = http://localhost:8585 (the server URL)
  • Instance field = myinstance (the user-given name)

So a naive lookup by context name alone (ResolveContext(myinstance)) fails — there is no context literally named myinstance. The existing ResolveContext expects the context's name field, not the Instance field.

Solution

This PR adds a --name flag to microcks stop with a two-tier fallback resolution:

  1. Try as a context name — works for contexts created via microcks login --name dev (stored as Context{Name: "dev"})
  2. Scan contexts by Instance field — works for contexts created via microcks start --name myinstance (stored as ContextRef{Name: "http://...", Instance: "myinstance"})

If neither lookup succeeds, the user receives a clear error message.

When --name is omitted, behavior is 100% identical to the current code (uses the current context).

Changes

cmd/stop.go — 29 insertions, 2 deletions:

  • Added var name string for the flag variable
  • Added Example help text with usage patterns
  • Added two-tier context resolution logic
  • Registered the --name flag on stopCmd

Verification

Check Result
go build ./... ✅ Compiles cleanly
All existing tests ✅ Pass (26/27 pass; TestDeleteContext failure is pre-existing)
Backward compatible ✅ No flag = unchanged behavior

Example Usage

# Stop the instance from the current context (existing behavior)
microcks stop

# Stop by context name (useful after login --name)
microcks stop --name dev-context

# Stop by instance name (useful after start --name)
microcks stop --name myinstance

Fixes #438

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>
Copilot AI review requested due to automatic review settings June 17, 2026 03:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 --name flag to microcks stop with 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 thread cmd/stop.go
Comment on lines +41 to +46
for _, c := range localConfig.Contexts {
if c.Instance == name {
ctxRef = &c
break
}
}
Comment thread cmd/stop.go
Comment on lines +47 to +49
if ctxRef == nil {
log.Fatalf("No context found for '%s'", name)
}
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.

fix: stop command missing --name flag to specify which instance to stop

2 participants