Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 i := range localConfig.Contexts {
if localConfig.Contexts[i].Instance == name {
ctxRef = &localConfig.Contexts[i]
break
}
}
if ctxRef == nil {
log.Fatalf("No context found for '%s'", name)
}
Comment on lines +47 to +49
ctx, err = localConfig.ResolveContext(ctxRef.Name)
errors.CheckError(err)
}
} else {
ctx, err = localConfig.ResolveContext("")
errors.CheckError(err)
}
instance := ctx.Instance

if instance.Name == "" {
Expand Down Expand Up @@ -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
}