77 "github.com/microsoft/go-sqlcmd/cmd/modern/root"
88 "github.com/microsoft/go-sqlcmd/internal/cmdparser"
99 "github.com/microsoft/go-sqlcmd/internal/config"
10+ "runtime"
1011)
1112
1213// Root type implements the very top-level command for sqlcmd (which contains
@@ -23,17 +24,23 @@ type Root struct {
2324// It sets the cli name, description, and subcommands, and adds global flags.
2425// It also provides usage examples for sqlcmd.
2526func (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 }}
3340
3441 commandOptions := cmdparser.CommandOptions {
3542 Use : "sqlcmd" ,
36- Short : "sqlcmd: command-line interface for the #SQLFamily " ,
43+ Short : "sqlcmd: Install/Create/Query SQL Server, Azure SQL, and Tools " ,
3744 SubCommands : c .SubCommands (),
3845 Examples : examples ,
3946 }
@@ -47,12 +54,21 @@ func (c *Root) DefineCommand(...cmdparser.CommandOptions) {
4754func (c * Root ) SubCommands () []cmdparser.Command {
4855 dependencies := c .Dependencies ()
4956
50- return []cmdparser.Command {
57+ subCommands := []cmdparser.Command {
5158 cmdparser.New [* root.Config ](dependencies ),
5259 cmdparser.New [* root.Install ](dependencies ),
5360 cmdparser.New [* root.Query ](dependencies ),
61+ cmdparser.New [* root.Start ](dependencies ),
62+ cmdparser.New [* root.Stop ](dependencies ),
5463 cmdparser.New [* root.Uninstall ](dependencies ),
5564 }
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
5672}
5773
5874// Execute runs the application based on the command-line
@@ -70,47 +86,28 @@ func (c *Root) IsValidSubCommand(command string) bool {
7086}
7187
7288func (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-
9489 c .AddFlag (cmdparser.FlagOptions {
9590 String : & c .configFilename ,
9691 DefaultString : config .DefaultFileName (),
9792 Name : "sqlconfig" ,
9893 Usage : "Configuration file" ,
9994 })
10095
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.
10198 c.AddFlag(cmdparser.FlagOptions{
10299 String: &c.outputType,
103- DefaultString : "yaml " ,
100+ DefaultString: "json ",
104101 Name: "output",
105102 Shorthand: "o",
106103 Usage: "output type (yaml, json or xml)",
107104 })
105+ */
108106
109107 c .AddFlag (cmdparser.FlagOptions {
110108 Int : (* int )(& c .loggingLevel ),
111109 DefaultInt : 2 ,
112110 Name : "verbosity" ,
113- Shorthand : "v" ,
114111 Usage : "Log level, error=0, warn=1, info=2, debug=3, trace=4" ,
115112 })
116113}
0 commit comments