-
Notifications
You must be signed in to change notification settings - Fork 56
/
config.go
62 lines (54 loc) · 2.27 KB
/
config.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
54
55
56
57
58
59
60
61
62
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package root
import (
"fmt"
"github.com/microsoft/go-sqlcmd/cmd/modern/root/config"
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
"github.com/microsoft/go-sqlcmd/internal/localizer"
"github.com/microsoft/go-sqlcmd/internal/pal"
)
// Config defines the `sqlcmd config` sub-commands
type Config struct {
cmdparser.Cmd
}
// DefineCommand defines the `sqlcmd config` command, which is only
// more sub-commands (`sqlcmd config` does not `run` anything itself)
func (c *Config) DefineCommand(...cmdparser.CommandOptions) {
options := cmdparser.CommandOptions{
Use: "config",
Short: localizer.Sprintf(`Modify sqlconfig files using subcommands like "%s"`, localizer.UseContextCommand),
SubCommands: c.SubCommands(),
Examples: []cmdparser.ExampleOptions{
{
Description: localizer.Sprintf("Add context for existing endpoint and user (use %s or %s)", localizer.PasswordEnvVar, localizer.PasswordEnvVar2),
Steps: []string{
fmt.Sprintf("%s SQLCMD_PASSWORD=<placeholderpassword>", pal.CreateEnvVarKeyword()),
"sqlcmd config add-user --name sa1434 --username sa",
fmt.Sprintf("%s SQLCMD_PASSWORD=", pal.CreateEnvVarKeyword()),
"sqlcmd config add-endpoint --name ep1434 --address localhost --port 1434",
"sqlcmd config add-context --name mssql1434 --user sa1434 --endpoint ep1434"},
},
},
}
c.Cmd.DefineCommand(options)
}
// SubCommands sets up all the sub-commands for `sqlcmd config`
func (c *Config) SubCommands() []cmdparser.Command {
dependencies := c.Dependencies()
return []cmdparser.Command{
cmdparser.New[*config.AddContext](dependencies),
cmdparser.New[*config.AddEndpoint](dependencies),
cmdparser.New[*config.AddUser](dependencies),
cmdparser.New[*config.ConnectionStrings](dependencies),
cmdparser.New[*config.CurrentContext](dependencies),
cmdparser.New[*config.DeleteContext](dependencies),
cmdparser.New[*config.DeleteEndpoint](dependencies),
cmdparser.New[*config.DeleteUser](dependencies),
cmdparser.New[*config.GetContexts](dependencies),
cmdparser.New[*config.GetEndpoints](dependencies),
cmdparser.New[*config.GetUsers](dependencies),
cmdparser.New[*config.UseContext](dependencies),
cmdparser.New[*config.View](dependencies),
}
}