Skip to content

Commit 6d574a9

Browse files
authored
Merge pull request #240 from microsoft/stuartpa/bug-bash-feedback
Stuartpa/bug bash feedback
2 parents be72914 + 2e5f77b commit 6d574a9

File tree

13 files changed

+68
-20
lines changed

13 files changed

+68
-20
lines changed

cmd/modern/root.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type Root struct {
2525
// It also provides usage examples for sqlcmd.
2626
func (c *Root) DefineCommand(...cmdparser.CommandOptions) {
2727
// Example usage steps
28-
steps := []string{"sqlcmd create mssql --using https://aka.ms/AdventureWorksLT.bak"}
28+
steps := []string{"sqlcmd create mssql --accept-eula --using https://aka.ms/AdventureWorksLT.bak"}
2929

3030
if runtime.GOOS == "windows" {
3131
steps = append(steps, "sqlcmd open ads")
@@ -39,8 +39,11 @@ func (c *Root) DefineCommand(...cmdparser.CommandOptions) {
3939
Steps: steps}}
4040

4141
commandOptions := cmdparser.CommandOptions{
42-
Use: "sqlcmd",
43-
Short: "sqlcmd: Install/Create/Query SQL Server, Azure SQL, and Tools",
42+
Use: "sqlcmd",
43+
Short: `sqlcmd: Install/Create/Query SQL Server, Azure SQL, and Tools
44+
45+
Feedback:
46+
https://github.com/microsoft/go-sqlcmd/issues/new`,
4447
SubCommands: c.SubCommands(),
4548
Examples: examples,
4649
}
@@ -86,6 +89,18 @@ func (c *Root) IsValidSubCommand(command string) bool {
8689
}
8790

8891
func (c *Root) addGlobalFlags() {
92+
93+
// BUG:(stuartpa) - This is a temporary flag until we have migrated
94+
// the kong impl to cobra. sqlcmd -? will show the kong help (all the back-compat
95+
// flags), sqlcmd --? will show the kong "did you mean one of" help.
96+
var unused bool
97+
c.AddFlag(cmdparser.FlagOptions{
98+
Bool: &unused,
99+
Name: "?",
100+
Shorthand: "?",
101+
Usage: "help for backwards compatibility flags (-S, -U, -E etc.)",
102+
})
103+
89104
c.AddFlag(cmdparser.FlagOptions{
90105
String: &c.configFilename,
91106
DefaultString: config.DefaultFileName(),

cmd/modern/root/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package root
55

66
import (
7+
"fmt"
78
"github.com/microsoft/go-sqlcmd/cmd/modern/root/config"
89
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
10+
"github.com/microsoft/go-sqlcmd/internal/pal"
911
)
1012

1113
// Config defines the `sqlcmd config` sub-commands
@@ -20,6 +22,17 @@ func (c *Config) DefineCommand(...cmdparser.CommandOptions) {
2022
Use: "config",
2123
Short: `Modify sqlconfig files using subcommands like "sqlcmd config use-context mssql"`,
2224
SubCommands: c.SubCommands(),
25+
Examples: []cmdparser.ExampleOptions{
26+
{
27+
Description: "Add context for existing endpoint and user",
28+
Steps: []string{
29+
fmt.Sprintf("%s SQLCMD_PASSWORD=<password>", pal.CreateEnvVarKeyword()),
30+
"sqlcmd config add-user --name sa1434 --username sa",
31+
fmt.Sprintf("%s SQLCMD_PASSWORD=", pal.CreateEnvVarKeyword()),
32+
"sqlcmd config add-endpoint --name ep1434 --address localhost --port 1434",
33+
"sqlcmd config add-context --name mssql1434 --user sa1434 --endpoint ep1434"},
34+
},
35+
},
2336
}
2437

2538
c.Cmd.DefineCommand(options)

cmd/modern/root/config/add-context.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ func (c *AddContext) DefineCommand(...cmdparser.CommandOptions) {
2626
Short: "Add a context",
2727
Examples: []cmdparser.ExampleOptions{
2828
{
29-
Description: "Add a default context",
30-
Steps: []string{"sqlcmd config add-context --name my-context"}},
29+
Description: "Add a context for a local instance of SQL Server on port 1433 using trusted authentication",
30+
Steps: []string{
31+
"sqlcmd config add-endpoint --name localhost-1433",
32+
"sqlcmd config add-context --name mssql --endpoint localhost-1433"}},
3133
},
3234
Run: c.run}
3335

@@ -42,12 +44,12 @@ func (c *AddContext) DefineCommand(...cmdparser.CommandOptions) {
4244
c.AddFlag(cmdparser.FlagOptions{
4345
String: &c.endpointName,
4446
Name: "endpoint",
45-
Usage: "Name of endpoint this context will use, use `sqlcmd config get-endpoints` to see list"})
47+
Usage: "Name of endpoint this context will use"})
4648

4749
c.AddFlag(cmdparser.FlagOptions{
4850
String: &c.userName,
4951
Name: "user",
50-
Usage: "Name of user this context will use, use `sqlcmd config get-users` to see list"})
52+
Usage: "Name of user this context will use"})
5153
}
5254

5355
// run adds a context to the configuration and sets it as the current context. The

cmd/modern/root/config/add-user.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package config
55

66
import (
7+
"fmt"
78
"github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
9+
"github.com/microsoft/go-sqlcmd/internal/pal"
810
"os"
911

1012
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
@@ -30,8 +32,10 @@ func (c *AddUser) DefineCommand(...cmdparser.CommandOptions) {
3032
{
3133
Description: "Add a user",
3234
Steps: []string{
33-
`SET SQLCMD_PASSWORD="AComp!exPa$$w0rd"`,
34-
"sqlcmd config add-user --name my-user --name user1"},
35+
fmt.Sprintf(`%s SQLCMD_PASSWORD=<password>`, pal.CreateEnvVarKeyword()),
36+
"sqlcmd config add-user --name my-user --username user1",
37+
fmt.Sprintf(`%s SQLCMD_PASSWORD=`, pal.CreateEnvVarKeyword()),
38+
},
3539
},
3640
},
3741
Run: c.run}

cmd/modern/root/config/add-user_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ func (c *AddUser) encryptPasswordFlag() {
99
c.AddFlag(cmdparser.FlagOptions{
1010
Bool: &c.encryptPassword,
1111
Name: "encrypt-password",
12-
Usage: "Encode the password",
12+
Usage: "Encrypt the password",
1313
})
1414
}

cmd/modern/root/config/delete-context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (c *DeleteContext) run() {
6464

6565
if c.cascade {
6666
config.DeleteEndpoint(context.Endpoint)
67-
if *context.ContextDetails.User != "" {
67+
if context.ContextDetails.User != nil && *context.ContextDetails.User != "" {
6868
config.DeleteUser(*context.ContextDetails.User)
6969
}
7070
}

cmd/modern/root/config/view.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func (c *View) DefineCommand(...cmdparser.CommandOptions) {
2121
Short: "Display merged sqlconfig settings or a specified sqlconfig file",
2222
Examples: []cmdparser.ExampleOptions{
2323
{
24-
Description: "Show merged sqlconfig settings",
24+
Description: "Show sqlconfig settings, with REDACTED authentication data",
2525
Steps: []string{"sqlcmd config view"},
2626
},
2727
{
28-
Description: "Show merged sqlconfig settings and raw authentication data",
28+
Description: "Show sqlconfig settings and raw authentication data",
2929
Steps: []string{"sqlcmd config view --raw"},
3030
},
3131
},
32-
Aliases: []string{"use", "change-context", "set-context"},
32+
Aliases: []string{"show"},
3333
Run: c.run,
3434
}
3535

cmd/modern/root/open/ads_windows.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ func (c *Ads) removePreviousCredential() {
7777

7878
// writeCredential stores the current instance's credential in the Windows Credential Manager
7979
func (c *Ads) writeCredential() {
80+
output := c.Output()
81+
8082
err := credman.WriteCredential(&c.credential, credman.CredTypeGeneric)
81-
c.CheckErr(err)
83+
if err != nil {
84+
output.FatalfErrorWithHints(
85+
err,
86+
[]string{"A 'Not enough memory resources are available' error can be caused by too many credentials already stored in Windows Credential Manager"},
87+
"Failed to write credential to Windows Credential Manager")
88+
}
8289
}

cmd/modern/root/uninstall.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package root
55

66
import (
77
"fmt"
8-
"path/filepath"
98
"strings"
109

1110
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
@@ -158,7 +157,7 @@ func (c *Uninstall) userDatabaseSafetyCheck(controller *container.Controller, id
158157
output.FatalfWithHints([]string{
159158
fmt.Sprintf(
160159
"If the database is mounted, run `sqlcmd query \"use master; DROP DATABASE [%s]\"`",
161-
strings.TrimSuffix(filepath.Base(databaseFile), ".mdf")),
160+
"<database_name>"),
162161
"Pass in the flag --force to override this safety check for user (non-system) databases"},
163162
"Unable to continue, a user (non-system) database (%s) is present", databaseFile)
164163
}

cmd/modern/sqlconfig/sqlconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type Endpoint struct {
3131

3232
type ContextDetails struct {
3333
Endpoint string `mapstructure:"endpoint"`
34-
User *string `mapstructure:"user,omitempty"`
34+
User *string `mapstructure:"user,omitempty" yaml:"user,omitempty"`
3535
}
3636

3737
type Context struct {

0 commit comments

Comments
 (0)