From e4b8904f70eceaae370c184073cca74151c718e8 Mon Sep 17 00:00:00 2001 From: Adesh Deshmukh Date: Wed, 17 Jun 2026 09:04:06 +0530 Subject: [PATCH 1/2] fix(stop): add --name flag to stop named contexts and instances 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 #438 Signed-off-by: Adesh Deshmukh --- cmd/stop.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cmd/stop.go b/cmd/stop.go index eaba91fd..6363a99a 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -11,11 +11,17 @@ import ( ) func NewStopCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { + var name string var stopCmd = &cobra.Command{ Use: "stop", Short: "stop microcks instance", Long: "stop microcks instance", + Example: `# Stop the instance from the current context +microcks stop + +# Stop by context name or instance name +microcks stop --name myinstance`, Run: func(cmd *cobra.Command, args []string) { configFile := globalClientOpts.ConfigPath @@ -27,8 +33,27 @@ func NewStopCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { return } - ctx, err := localConfig.ResolveContext("") - errors.CheckError(err) + var ctx *config.Context + if name != "" { + ctx, err = localConfig.ResolveContext(name) + if err != nil { + var ctxRef *config.ContextRef + for _, c := range localConfig.Contexts { + if c.Instance == name { + ctxRef = &c + break + } + } + if ctxRef == nil { + log.Fatalf("No context found for '%s'", name) + } + ctx, err = localConfig.ResolveContext(ctxRef.Name) + errors.CheckError(err) + } + } else { + ctx, err = localConfig.ResolveContext("") + errors.CheckError(err) + } instance := ctx.Instance if instance.Name == "" { @@ -73,5 +98,7 @@ func NewStopCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command { }, } + stopCmd.Flags().StringVar(&name, "name", "", "Name of the context or instance to stop (uses current context if empty)") + return stopCmd } From 3d52be80243b7737ab84a59100f6541e9c7676ea Mon Sep 17 00:00:00 2001 From: Adesh Deshmukh Date: Sun, 21 Jun 2026 17:33:25 +0530 Subject: [PATCH 2/2] fix(stop): use indexed loop for pointer-safe context lookup Signed-off-by: Adesh Deshmukh --- cmd/stop.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/stop.go b/cmd/stop.go index 6363a99a..ccea24d4 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -38,9 +38,9 @@ microcks stop --name myinstance`, ctx, err = localConfig.ResolveContext(name) if err != nil { var ctxRef *config.ContextRef - for _, c := range localConfig.Contexts { - if c.Instance == name { - ctxRef = &c + for i := range localConfig.Contexts { + if localConfig.Contexts[i].Instance == name { + ctxRef = &localConfig.Contexts[i] break } }