7
7
"github.com/microsoft/go-sqlcmd/cmd/modern/root"
8
8
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
9
9
"github.com/microsoft/go-sqlcmd/internal/config"
10
+ "runtime"
10
11
)
11
12
12
13
// Root type implements the very top-level command for sqlcmd (which contains
@@ -23,17 +24,23 @@ type Root struct {
23
24
// It sets the cli name, description, and subcommands, and adds global flags.
24
25
// It also provides usage examples for sqlcmd.
25
26
func (c * Root ) DefineCommand (... cmdparser.CommandOptions ) {
26
- examples := []cmdparser.ExampleOptions {
27
- {
28
- Description : "Install, Query, Uninstall SQL Server" ,
29
- Steps : []string {
30
- "sqlcmd install mssql" ,
31
- `sqlcmd query "SELECT @@version"` ,
32
- "sqlcmd uninstall" }}}
27
+ // Example usage steps
28
+ steps := []string {"sqlcmd create mssql --using https://aka.ms/AdventureWorksLT.bak" }
29
+
30
+ if runtime .GOOS == "windows" {
31
+ steps = append (steps , "sqlcmd open ads" )
32
+ }
33
+
34
+ steps = append (steps , `sqlcmd query "SELECT @version"` )
35
+ steps = append (steps , "sqlcmd delete" )
36
+
37
+ examples := []cmdparser.ExampleOptions {{
38
+ Description : "Install/Create, Query, Uninstall SQL Server" ,
39
+ Steps : steps }}
33
40
34
41
commandOptions := cmdparser.CommandOptions {
35
42
Use : "sqlcmd" ,
36
- Short : "sqlcmd: command-line interface for the #SQLFamily " ,
43
+ Short : "sqlcmd: Install/Create/Query SQL Server, Azure SQL, and Tools " ,
37
44
SubCommands : c .SubCommands (),
38
45
Examples : examples ,
39
46
}
@@ -47,12 +54,21 @@ func (c *Root) DefineCommand(...cmdparser.CommandOptions) {
47
54
func (c * Root ) SubCommands () []cmdparser.Command {
48
55
dependencies := c .Dependencies ()
49
56
50
- return []cmdparser.Command {
57
+ subCommands := []cmdparser.Command {
51
58
cmdparser.New [* root.Config ](dependencies ),
52
59
cmdparser.New [* root.Install ](dependencies ),
53
60
cmdparser.New [* root.Query ](dependencies ),
61
+ cmdparser.New [* root.Start ](dependencies ),
62
+ cmdparser.New [* root.Stop ](dependencies ),
54
63
cmdparser.New [* root.Uninstall ](dependencies ),
55
64
}
65
+
66
+ // BUG:(stuartpa) - Add Mac / Linux support
67
+ if runtime .GOOS == "windows" {
68
+ subCommands = append (subCommands , cmdparser.New [* root.Open ](dependencies ))
69
+ }
70
+
71
+ return subCommands
56
72
}
57
73
58
74
// Execute runs the application based on the command-line
@@ -70,47 +86,28 @@ func (c *Root) IsValidSubCommand(command string) bool {
70
86
}
71
87
72
88
func (c * Root ) addGlobalFlags () {
73
- c .AddFlag (cmdparser.FlagOptions {
74
- Bool : & globalOptions .TrustServerCertificate ,
75
- Name : "trust-server-certificate" ,
76
- Shorthand : "C" ,
77
- Usage : "Whether to trust the certificate presented by the endpoint for encryption" ,
78
- })
79
-
80
- c .AddFlag (cmdparser.FlagOptions {
81
- String : & globalOptions .DatabaseName ,
82
- Name : "database-name" ,
83
- Shorthand : "d" ,
84
- Usage : "The initial database for the connection" ,
85
- })
86
-
87
- c .AddFlag (cmdparser.FlagOptions {
88
- Bool : & globalOptions .UseTrustedConnection ,
89
- Name : "use-trusted-connection" ,
90
- Shorthand : "E" ,
91
- Usage : "Whether to use integrated security" ,
92
- })
93
-
94
89
c .AddFlag (cmdparser.FlagOptions {
95
90
String : & c .configFilename ,
96
91
DefaultString : config .DefaultFileName (),
97
92
Name : "sqlconfig" ,
98
93
Usage : "Configuration file" ,
99
94
})
100
95
96
+ /* BUG:(stuartpa) - At the moment this is a top level flag, but it doesn't
97
+ work with all sub-commands (e.g. query), so removing for now.
101
98
c.AddFlag(cmdparser.FlagOptions{
102
99
String: &c.outputType,
103
- DefaultString : "yaml " ,
100
+ DefaultString: "json ",
104
101
Name: "output",
105
102
Shorthand: "o",
106
103
Usage: "output type (yaml, json or xml)",
107
104
})
105
+ */
108
106
109
107
c .AddFlag (cmdparser.FlagOptions {
110
108
Int : (* int )(& c .loggingLevel ),
111
109
DefaultInt : 2 ,
112
110
Name : "verbosity" ,
113
- Shorthand : "v" ,
114
111
Usage : "Log level, error=0, warn=1, info=2, debug=3, trace=4" ,
115
112
})
116
113
}
0 commit comments