-
Notifications
You must be signed in to change notification settings - Fork 56
/
stop.go
53 lines (45 loc) · 1.52 KB
/
stop.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package root
import (
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
"github.com/microsoft/go-sqlcmd/internal/config"
"github.com/microsoft/go-sqlcmd/internal/container"
"github.com/microsoft/go-sqlcmd/internal/localizer"
)
type Stop struct {
cmdparser.Cmd
}
func (c *Stop) DefineCommand(...cmdparser.CommandOptions) {
options := cmdparser.CommandOptions{
Use: "stop",
Short: localizer.Sprintf("Stop current context"),
Examples: []cmdparser.ExampleOptions{
{
Description: localizer.Sprintf("Stop the current context"),
Steps: []string{`sqlcmd stop`}},
},
Run: c.run,
}
c.Cmd.DefineCommand(options)
}
func (c *Stop) run() {
output := c.Output()
if config.CurrentContextName() == "" {
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("To view available contexts"), "sqlcmd config get-contexts"},
}, localizer.Sprintf("No current context"))
}
if config.CurrentContextEndpointHasContainer() {
controller := container.NewController()
id := config.ContainerId()
endpoint, _ := config.CurrentContext()
output.Info(localizer.Sprintf("Stopping %q for context %q", endpoint.ContainerDetails.Image, config.CurrentContextName()))
err := controller.ContainerStop(id)
c.CheckErr(err)
} else {
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("Create a new context with a SQL Server container "), "sqlcmd create mssql"},
}, localizer.Sprintf("Current context does not have a container"))
}
}