Skip to content

Commit

Permalink
Merge branch 'app_insights' of github.com:microsoft/go-sqlcmd into ap…
Browse files Browse the repository at this point in the history
…p_insights
  • Loading branch information
JyotikaGargg committed Aug 1, 2023
2 parents ad3bf3f + 102b24a commit 42b9e4e
Show file tree
Hide file tree
Showing 52 changed files with 15,541 additions and 4,839 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ Learn more about how `sqlcmd` is used from a articles/posts written by the commu
| --------------------- | --------------------- |
| `brew install sqlcmd` | `brew upgrade sqlcmd` |

##### Apple Silicon Macs (M1/M2)
Macs running Apple Silicon require [Docker][] Desktop to use Rosetta for x86/amd64 emulation. Follow these steps before creating a SQL Server instance:
- Open Docker Desktop.
- Go to the settings/preferences menu.
- Find the “Features in development” section.
- Enable the "Use Rosetta for x86/amd64 emulation on Apple Silicon" checkbox.

### Linux

`sqlcmd` is available via [Linuxbrew][], and as a downloadable .rpm/.deb and .tar from the [releases page][].
Expand Down
6 changes: 3 additions & 3 deletions cmd/modern/root/config/add-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *AddContext) run() {
}

if c.endpointName == "" || !config.EndpointExists(c.endpointName) {
output.FatalfWithHintExamples([][]string{
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("View existing endpoints to choose from"), "sqlcmd config get-endpoints"},
{localizer.Sprintf("Add a new local endpoint"), "sqlcmd create"},
{localizer.Sprintf("Add an already existing endpoint"), "sqlcmd config add-endpoint --address localhost --port 1433"}},
Expand All @@ -78,7 +78,7 @@ func (c *AddContext) run() {

if c.userName != "" {
if !config.UserNameExists(c.userName) {
output.FatalfWithHintExamples([][]string{
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("View list of users"), "sqlcmd config get-users"},
{localizer.Sprintf("Add the user"), fmt.Sprintf("sqlcmd config add-user --name %v", c.userName)},
{localizer.Sprintf("Add an endpoint"), "sqlcmd create"}},
Expand All @@ -88,7 +88,7 @@ func (c *AddContext) run() {

context.Name = config.AddContext(context)
config.SetCurrentContextName(context.Name)
output.InfofWithHintExamples([][]string{
output.InfoWithHintExamples([][]string{
{localizer.Sprintf("Open in Azure Data Studio"), "sqlcmd open ads"},
{localizer.Sprintf("To start interactive query session"), "sqlcmd query"},
{localizer.Sprintf("To run a query"), "sqlcmd query \"SELECT @@version\""},
Expand Down
2 changes: 1 addition & 1 deletion cmd/modern/root/config/add-endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *AddEndpoint) run() {
}

uniqueEndpointName := config.AddEndpoint(endpoint)
output.InfofWithHintExamples([][]string{
output.InfoWithHintExamples([][]string{
{localizer.Sprintf("Add a context for this endpoint"), fmt.Sprintf("sqlcmd config add-context --endpoint %v", uniqueEndpointName)},
{localizer.Sprintf("View endpoint names"), "sqlcmd config get-endpoints"},
{localizer.Sprintf("View endpoint details"), fmt.Sprintf("sqlcmd config get-endpoints %v", uniqueEndpointName)},
Expand Down
8 changes: 4 additions & 4 deletions cmd/modern/root/config/add-user.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (c *AddUser) run() {

if c.authType != "basic" &&
c.authType != "other" {
output.FatalfWithHints([]string{localizer.Sprintf("Authentication type must be '%s' or '%s'", localizer.ModernAuthTypeBasic, localizer.ModernAuthTypeOther)},
output.FatalWithHints([]string{localizer.Sprintf("Authentication type must be '%s' or '%s'", localizer.ModernAuthTypeBasic, localizer.ModernAuthTypeOther)},
localizer.Sprintf("Authentication type '' is not valid %v'", c.authType))
}

Expand Down Expand Up @@ -136,15 +136,15 @@ func (c *AddUser) run() {
}

if c.username == "" {
output.FatalfWithHintExamples([][]string{
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("Provide a username with the %s flag"),
"sqlcmd config add-user --username sa"},
},
localizer.Sprintf("Username not provided"))
}

if !secret.IsValidEncryptionMethod(c.passwordEncryption) {
output.FatalfWithHints([]string{
output.FatalWithHints([]string{
localizer.Sprintf("Provide a valid encryption method (%s) with the %s flag", secret.EncryptionMethodsForUsage(), localizer.PasswordEncryptFlag)},
localizer.Sprintf("Encryption method '%v' is not valid", c.passwordEncryption))
}
Expand All @@ -168,5 +168,5 @@ func (c *AddUser) run() {
}

uniqueUserName := config.AddUser(user)
output.Infof(localizer.Sprintf("User '%v' added", uniqueUserName))
output.Info(localizer.Sprintf("User '%v' added", uniqueUserName))
}
2 changes: 1 addition & 1 deletion cmd/modern/root/config/connection-strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *ConnectionStrings) run() {
output.Infof("%-8s %s", k+":", v)
}
} else {
output.Infof(localizer.Sprintf("Connection Strings only supported for %s Auth type", localizer.ModernAuthTypeBasic))
output.Info(localizer.Sprintf("Connection Strings only supported for %s Auth type", localizer.ModernAuthTypeBasic))
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/modern/root/config/delete-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func (c *DeleteContext) run() {

config.DeleteContext(c.name)

output.Infof(localizer.Sprintf("Context '%v' deleted", c.name))
output.Info(localizer.Sprintf("Context '%v' deleted", c.name))
} else {
output.FatalfWithHintExamples([][]string{
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("View available contexts"), "sqlcmd config get-contexts"},
},
localizer.Sprintf("Context '%v' does not exist", c.name))
Expand Down
4 changes: 2 additions & 2 deletions cmd/modern/root/config/delete-endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (c *DeleteEndpoint) run() {
if config.EndpointExists(c.name) {
config.DeleteEndpoint(c.name)
} else {
output.FatalfWithHintExamples([][]string{
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("View endpoints"), "sqlcmd config get-endpoints"},
},
localizer.Sprintf("Endpoint '%v' does not exist", c.name))
}

output.Infof(localizer.Sprintf("Endpoint '%v' deleted", c.name))
output.Info(localizer.Sprintf("Endpoint '%v' deleted", c.name))
}
4 changes: 2 additions & 2 deletions cmd/modern/root/config/delete-user.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func (c *DeleteUser) run() {
if config.UserNameExists(c.name) {
config.DeleteUser(c.name)
} else {
output.FatalfWithHintExamples([][]string{
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("View users"), "sqlcmd config get-users"},
},
localizer.Sprintf("User %q does not exist", c.name))
}

output.Infof(localizer.Sprintf("User %q deleted", c.name))
output.Info(localizer.Sprintf("User %q deleted", c.name))
}
2 changes: 1 addition & 1 deletion cmd/modern/root/config/get-contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *GetContexts) run() {
context := config.GetContext(c.name)
output.Struct(context)
} else {
output.FatalfWithHints(
output.FatalWithHints(
[]string{localizer.Sprintf("To view available contexts run `%s`", localizer.GetContextCommand)},
localizer.Sprintf("error: no context exists with the name: \"%v\"", c.name))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/modern/root/config/get-endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *GetEndpoints) run() {
context := config.GetEndpoint(c.name)
output.Struct(context)
} else {
output.FatalfWithHints(
output.FatalWithHints(
[]string{localizer.Sprintf("To view available endpoints run `%s`", localizer.GetEndpointsCommand)},
localizer.Sprintf("error: no endpoint exists with the name: \"%v\"", c.name))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/modern/root/config/get-users.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *GetUsers) run() {
user := config.GetUser(c.name)
output.Struct(user)
} else {
output.FatalfWithHints(
output.FatalWithHints(
[]string{localizer.Sprintf("To view available users run `%s`", localizer.GetUsersCommand)},
localizer.Sprintf("error: no user exists with the name: \"%v\"", c.name))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/modern/root/config/use-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (c *UseContext) run() {

if config.ContextExists(c.name) {
config.SetCurrentContextName(c.name)
output.InfofWithHints([]string{
output.InfoWithHints([]string{
localizer.Sprintf("To run a query: %s", localizer.RunQueryExample),
localizer.Sprintf("To remove: %s", localizer.UninstallCommand)},
localizer.Sprintf("Switched to context \"%v\".", c.name))
} else {
output.FatalfWithHints([]string{localizer.Sprintf("To view available contexts run `%s`", localizer.GetContextCommand)},
output.FatalWithHints([]string{localizer.Sprintf("To view available contexts run `%s`", localizer.GetContextCommand)},
localizer.Sprintf("No context exists with the name: \"%v\"", c.name))
}
}
28 changes: 14 additions & 14 deletions cmd/modern/root/install/mssql-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (c *MssqlBase) createContainer(imageName string, contextName string) {
c.downloadImage(imageName, output, controller)
}

output.Infof(localizer.Sprintf("Starting %v", imageName))
output.Info(localizer.Sprintf("Starting %v", imageName))
containerId := controller.ContainerRun(
imageName,
env,
Expand Down Expand Up @@ -319,15 +319,15 @@ func (c *MssqlBase) createContainer(imageName string, contextName string) {
c.passwordEncryption,
)

output.Infof(
output.Info(
localizer.Sprintf("Created context %q in \"%s\", configuring user account...",
config.CurrentContextName(),
config.GetConfigFileUsed()))

controller.ContainerWaitForLogEntry(
containerId, c.errorLogEntryToWaitFor)

output.Infof(
output.Info(
localizer.Sprintf("Disabled %q account (and rotated %q password). Creating user %q",
"sa",
"sa",
Expand Down Expand Up @@ -390,7 +390,7 @@ func (c *MssqlBase) createContainer(imageName string, contextName string) {
hints = append(hints, []string{localizer.Sprintf("See connection strings"), "sqlcmd config connection-strings"})
hints = append(hints, []string{localizer.Sprintf("Remove"), "sqlcmd delete"})

output.InfofWithHintExamples(hints,
output.InfoWithHintExamples(hints,
localizer.Sprintf("Now ready for client connections on port %d",
c.port),
)
Expand All @@ -403,15 +403,15 @@ func (c *MssqlBase) validateUsingUrlExists() {
c.CheckErr(err)

if u.Scheme != "http" && u.Scheme != "https" {
output.FatalfWithHints(
output.FatalWithHints(
[]string{
localizer.Sprintf("--using URL must be http or https"),
},
localizer.Sprintf("%q is not a valid URL for --using flag", c.usingDatabaseUrl))
}

if u.Path == "" {
output.FatalfWithHints(
output.FatalWithHints(
[]string{
localizer.Sprintf("--using URL must have a path to .bak file"),
},
Expand All @@ -421,7 +421,7 @@ func (c *MssqlBase) validateUsingUrlExists() {
// At the moment we only support attaching .bak files, but we should
// support .bacpacs and .mdfs in the future
if _, file := filepath.Split(u.Path); filepath.Ext(file) != ".bak" {
output.FatalfWithHints(
output.FatalWithHints(
[]string{
localizer.Sprintf("--using file URL must be a .bak file"),
},
Expand Down Expand Up @@ -452,7 +452,7 @@ func (c *MssqlBase) createNonSaUser(
defaultDatabase = c.defaultDatabase

// Create the default database, if it isn't a downloaded database
output.Infof(localizer.Sprintf("Creating default database [%s]", defaultDatabase))
output.Info(localizer.Sprintf("Creating default database [%s]", defaultDatabase))
c.query(fmt.Sprintf("CREATE DATABASE [%s]", defaultDatabase))
}

Expand Down Expand Up @@ -532,7 +532,7 @@ func (c *MssqlBase) downloadAndRestoreDb(
_, file := filepath.Split(databaseUrl)

// Download file from URL into container
output.Infof(localizer.Sprintf("Downloading %s", file))
output.Info(localizer.Sprintf("Downloading %s", file))

temporaryFolder := "/var/opt/mssql/backup"

Expand All @@ -543,7 +543,7 @@ func (c *MssqlBase) downloadAndRestoreDb(
)

// Restore database from file
output.Infof(localizer.Sprintf("Restoring database %s", databaseName))
output.Info(localizer.Sprintf("Restoring database %s", databaseName))

dbNameAsIdentifier := getDbNameAsIdentifier(databaseName)
dbNameAsNonIdentifier := getDbNameAsNonIdentifier(databaseName)
Expand Down Expand Up @@ -603,10 +603,10 @@ func (c *MssqlBase) downloadImage(
output *output.Output,
controller *container.Controller,
) {
output.Infof(localizer.Sprintf("Downloading %v", imageName))
output.Info(localizer.Sprintf("Downloading %v", imageName))
err := controller.EnsureImage(imageName)
if err != nil || c.unitTesting {
output.FatalfErrorWithHints(
output.FatalErrorWithHints(
err,
[]string{
localizer.Sprintf("Is a container runtime installed on this machine (e.g. Podman or Docker)?") + pal.LineBreak() +
Expand All @@ -615,7 +615,7 @@ func (c *MssqlBase) downloadImage(
localizer.Sprintf("\t\tor") + pal.LineBreak() +
"\t\thttps://docs.docker.com/get-docker/",
localizer.Sprintf("Is a container runtime running? (Try `%s` or `%s` (list containers), does it return without error?)", localizer.PodmanPsCommand, localizer.DockerPsCommand),
fmt.Sprintf("If `podman ps` or `docker ps` works, try downloading the image with:"+pal.LineBreak()+
localizer.Sprintf("If `podman ps` or `docker ps` works, try downloading the image with:"+pal.LineBreak()+
"\t`podman|docker pull %s`", imageName)},
localizer.Sprintf("Unable to download image %s", imageName))
}
Expand All @@ -624,7 +624,7 @@ func (c *MssqlBase) downloadImage(
// Verify the file exists at the URL
func urlExists(url string, output *output.Output) {
if !http.UrlExists(url) {
output.FatalfWithHints(
output.FatalWithHints(
[]string{localizer.Sprintf("File does not exist at URL")},
localizer.Sprintf("Unable to download file"))
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/modern/root/open/ads.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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"
"github.com/microsoft/go-sqlcmd/internal/tools"
)

Expand Down Expand Up @@ -57,9 +58,9 @@ func (c *Ads) ensureContainerIsRunning(endpoint sqlconfig.Endpoint) {
output := c.Output()
controller := container.NewController()
if !controller.ContainerRunning(endpoint.AssetDetails.ContainerDetails.Id) {
output.FatalfWithHintExamples([][]string{
{"To start the container", "sqlcmd start"},
}, "Container is not running")
output.FatalWithHintExamples([][]string{
{localizer.Sprintf("To start the container"), localizer.Sprintf("sqlcmd start")},
}, localizer.Sprintf("Container is not running"))
}
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/modern/root/open/ads_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package open
import (
"github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
"github.com/microsoft/go-sqlcmd/internal/localizer"
)

// Type Ads is used to implement the "open ads" which launches Azure
Expand All @@ -28,9 +29,9 @@ func (c *Ads) persistCredentialForAds(hostname string, endpoint sqlconfig.Endpoi
func (c *Ads) displayPreLaunchInfo() {
output := c.Output()

output.Infof("Temporary: To view connection information run:")
output.Infof("")
output.Infof("\tsqlcmd config connection-strings")
output.Infof("")
output.Infof("(see issue for more information: https://github.com/microsoft/go-sqlcmd/issues/257)")
output.Info(localizer.Sprintf("Temporary: To view connection information run:"))
output.Info("")
output.Info("\tsqlcmd config connection-strings")
output.Info("")
output.Info("(see issue for more information: https://github.com/microsoft/go-sqlcmd/issues/257)")
}
10 changes: 6 additions & 4 deletions cmd/modern/root/open/ads_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package open

import (
"fmt"

"github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
"github.com/microsoft/go-sqlcmd/internal/credman"
"github.com/microsoft/go-sqlcmd/internal/localizer"
"github.com/microsoft/go-sqlcmd/internal/secret"
)

Expand All @@ -25,7 +27,7 @@ type Ads struct {
func (c *Ads) displayPreLaunchInfo() {
output := c.Output()

output.Infof("Press Ctrl+C to exit this process...")
output.Info(localizer.Sprintf("Press Ctrl+C to exit this process..."))
}

// persistCredentialForAds stores a SQL password in the Windows Credential Manager
Expand Down Expand Up @@ -92,9 +94,9 @@ func (c *Ads) writeCredential() {

err := credman.WriteCredential(&c.credential, credman.CredTypeGeneric)
if err != nil {
output.FatalfErrorWithHints(
output.FatalErrorWithHints(
err,
[]string{"A 'Not enough memory resources are available' error can be caused by too many credentials already stored in Windows Credential Manager"},
"Failed to write credential to Windows Credential Manager")
[]string{localizer.Sprintf("A 'Not enough memory resources are available' error can be caused by too many credentials already stored in Windows Credential Manager")},
localizer.Sprintf("Failed to write credential to Windows Credential Manager"))
}
}
Loading

0 comments on commit 42b9e4e

Please sign in to comment.