Skip to content

Commit bf7bb16

Browse files
committed
Saving changes
2 parents 75fc78c + 3a6fceb commit bf7bb16

File tree

142 files changed

+8238
-825
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+8238
-825
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ testresults.xml
2727
# IDE files
2828
.idea
2929

30+
darwin-amd64/sqlcmd
31+
darwin-arm64/sqlcmd
32+
linux-amd64/sqlcmd
33+
linux-arm64/sqlcmd
34+
linux-s390x/sqlcmd

build/arch.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
darwin,amd64,sqlcmd
2+
darwin,arm64,sqlcmd
3+
linux,amd64,sqlcmd
4+
linux,arm64,sqlcmd
5+
linux,s390x,sqlcmd
6+
windows,arm64,sqlcmd.exe
7+
windows,amd64,sqlcmd.exe
8+
windows,arm,sqlcmd.exe

build/azure-pipelines/build-product.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ stages:
3030
os:
3131
arch:
3232
binaryName: 'sqlcmd'
33+
macArm:
34+
imageName: 'macOS-latest'
35+
artifact: DarwinArm64
36+
os:
37+
arch: arm64
38+
binaryName: 'sqlcmd'
3339
windows:
3440
imageName: 'windows-latest'
3541
artifact: WindowsAmd64
@@ -43,11 +49,17 @@ stages:
4349
arch: arm64
4450
binaryName: 'sqlcmd'
4551
windowsArm:
52+
imageName: 'windows-latest'
53+
artifact: WindowsArm
54+
os:
55+
arch: arm
56+
binaryName: 'sqlcmd.exe'
57+
windowsArm64:
4658
imageName: 'windows-latest'
47-
artifact: WindowsArm
59+
artifact: WindowsArm64
4860
os:
49-
arch: arm
50-
binaryName: 'sqlcmd.exe'
61+
arch: arm64
62+
binaryName: 'sqlcmd.exe'
5163
linuxs390x:
5264
imageName: 'ubuntu-latest'
5365
artifact: LinuxS390x
@@ -136,18 +148,26 @@ stages:
136148
- task: ArchiveFiles@2
137149
displayName: Zip Windows amd64 binary
138150
inputs:
139-
rootFolderOrFile: '$(Pipeline.Workspace)\SqlcmdWindowsAmd64\Sqlcmd.exe'
151+
rootFolderOrFile: '$(Pipeline.Workspace)\SqlcmdWindowsAmd64'
140152
includeRootFolder: false
141153
archiveType: 'zip'
142154
archiveFile: '$(Build.ArtifactStagingDirectory)/sqlcmd-$(getVersion.VERSION_TAG)-windows-x64.zip'
143155

144156
- task: ArchiveFiles@2
145157
displayName: Zip Windows arm binary
146158
inputs:
147-
rootFolderOrFile: '$(Pipeline.Workspace)\SqlcmdWindowsArm\Sqlcmd.exe'
159+
rootFolderOrFile: '$(Pipeline.Workspace)\SqlcmdWindowsArm'
148160
includeRootFolder: false
149161
archiveType: 'zip'
150162
archiveFile: '$(Build.ArtifactStagingDirectory)/sqlcmd-$(getVersion.VERSION_TAG)-windows-arm.zip'
163+
164+
- task: ArchiveFiles@2
165+
displayName: Zip Windows arm64 binary
166+
inputs:
167+
rootFolderOrFile: '$(Pipeline.Workspace)\SqlcmdWindowsArm64'
168+
includeRootFolder: false
169+
archiveType: 'zip'
170+
archiveFile: '$(Build.ArtifactStagingDirectory)/sqlcmd-$(getVersion.VERSION_TAG)-windows-arm64.zip'
151171

152172
- task: ArchiveFiles@2
153173
displayName: Tar Linux amd64 binary
@@ -167,6 +187,15 @@ stages:
167187
tarCompression: 'bz2'
168188
archiveFile: '$(Build.ArtifactStagingDirectory)/sqlcmd-$(getVersion.VERSION_TAG)-darwin-x64.tar.bz2'
169189

190+
- task: ArchiveFiles@2
191+
displayName: Tar Darwin Arm binary
192+
inputs:
193+
rootFolderOrFile: '$(Pipeline.Workspace)\SqlcmdDarwinArm64'
194+
includeRootFolder: false
195+
archiveType: 'tar'
196+
tarCompression: 'bz2'
197+
archiveFile: '$(Build.ArtifactStagingDirectory)/sqlcmd-$(getVersion.VERSION_TAG)-darwin-arm64.tar.bz2'
198+
170199
- task: ArchiveFiles@2
171200
displayName: Tar Linux arm64 binary
172201
inputs:

build/build.cmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ go-licenses report github.com/microsoft/go-sqlcmd/cmd/modern --template build\NO
1313
copy %~dp0NOTICE.header + %~dp0notice.txt %~dp0..\NOTICE.md
1414
del %~dp0notice.txt
1515

16+
REM Generates all versions of sqlcmd in platform-specific folder
17+
setlocal
18+
19+
for /F "tokens=1-3 delims=," %%i in (%~dp0arch.txt) do set GOOS=%%i&set GOARCH=%%j&go build -o %~dp0..\%%i-%%j\%%k -ldflags="-X main.version=%sqlcmdVersion%" %~dp0..\cmd\modern
20+
1621

cmd/modern/main.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func main() {
4141
ErrorHandler: checkErr,
4242
HintHandler: displayHints})}
4343
rootCmd = cmdparser.New[*Root](dependencies)
44-
4544
if isFirstArgModernCliSubCommand() {
4645
cmdparser.Initialize(initializeCallback)
4746
rootCmd.Execute()
@@ -75,11 +74,6 @@ func initializeCallback() {
7574
OutputType: rootCmd.outputType,
7675
LoggingLevel: verbosity.Level(rootCmd.loggingLevel),
7776
})
78-
rootCmd.SetCrossCuttingConcerns(
79-
dependency.Options{
80-
EndOfLine: sqlcmd.SqlcmdEol,
81-
Output: outputter,
82-
})
8377
internal.Initialize(
8478
internal.InitializeOptions{
8579
ErrorHandler: checkErr,
@@ -95,7 +89,7 @@ func initializeCallback() {
9589
// nil. Pass (inject) checkErr into all dependencies (internal helpers etc.) as an
9690
// errorHandler.
9791
//
98-
// To aid debugging issues, if the logging level is > 2 (e.g. -v 3 or -v 4), we
92+
// To aid debugging issues, if the logging level is > 2 (e.g. --verbosity 3 or --verbosity 4), we
9993
// panic which outputs a stacktrace.
10094
func checkErr(err error) {
10195
if rootCmd.loggingLevel > 2 {
@@ -115,5 +109,6 @@ func displayHints(hints []string) {
115109
for i, hint := range hints {
116110
outputter.Infof(" %d. %v", i+1, hint)
117111
}
112+
outputter.Infof("")
118113
}
119114
}

cmd/modern/main_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ func TestInitializeCallback(t *testing.T) {
2727

2828
func TestDisplayHints(t *testing.T) {
2929
buf := test.NewMemoryBuffer()
30-
defer buf.Close()
30+
defer checkErr(buf.Close())
3131
outputter = output.New(output.Options{StandardWriter: buf})
3232
displayHints([]string{"This is a hint"})
3333
assert.Equal(t, pal.LineBreak()+
3434
"HINT:"+
3535
pal.LineBreak()+
36-
" 1. This is a hint"+pal.LineBreak(), buf.String())
36+
" 1. This is a hint"+pal.LineBreak()+pal.LineBreak(), buf.String())
3737
}
3838

3939
func TestCheckErr(t *testing.T) {
40-
defer func() { test.CatchExpectedError(recover(), t) }()
41-
42-
rootCmd = cmdparser.New[*Root](dependency.Options{})
43-
rootCmd.loggingLevel = 4
44-
checkErr(nil)
45-
checkErr(errors.New("test error"))
40+
assert.Panics(t, func() {
41+
rootCmd = cmdparser.New[*Root](dependency.Options{})
42+
rootCmd.loggingLevel = 4
43+
checkErr(nil)
44+
checkErr(errors.New("test error"))
45+
})
4646
}

cmd/modern/options.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ type GlobalOptions struct {
1818
Encrypt string
1919
DriverLogLevel int
2020
}
21-
22-
var globalOptions = &GlobalOptions{}

cmd/modern/root.go

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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.
2526
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}}
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) {
4754
func (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

7288
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-
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
}

cmd/modern/root/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func (c *Config) DefineCommand(...cmdparser.CommandOptions) {
2121
Short: `Modify sqlconfig files using subcommands like "sqlcmd config use-context mssql"`,
2222
SubCommands: c.SubCommands(),
2323
}
24+
2425
c.Cmd.DefineCommand(options)
2526
}
2627

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package config
55

66
import (
77
"fmt"
8+
89
"github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
910
"github.com/microsoft/go-sqlcmd/internal/cmdparser"
1011
"github.com/microsoft/go-sqlcmd/internal/config"
@@ -69,7 +70,7 @@ func (c *AddContext) run() {
6970
if c.endpointName == "" || !config.EndpointExists(c.endpointName) {
7071
output.FatalfWithHintExamples([][]string{
7172
{"View existing endpoints to choose from", "sqlcmd config get-endpoints"},
72-
{"Add a new local endpoint", "sqlcmd install"},
73+
{"Add a new local endpoint", "sqlcmd create"},
7374
{"Add an already existing endpoint", "sqlcmd config add-endpoint --address localhost --port 1433"}},
7475
"Endpoint required to add context. Endpoint '%v' does not exist. Use --endpoint flag", c.endpointName)
7576
}
@@ -79,14 +80,15 @@ func (c *AddContext) run() {
7980
output.FatalfWithHintExamples([][]string{
8081
{"View list of users", "sqlcmd config get-users"},
8182
{"Add the user", fmt.Sprintf("sqlcmd config add-user --name %v", c.userName)},
82-
{"Add an endpoint", "sqlcmd install"}},
83+
{"Add an endpoint", "sqlcmd create"}},
8384
"User '%v' does not exist", c.userName)
8485
}
8586
}
8687

87-
config.AddContext(context)
88+
context.Name = config.AddContext(context)
8889
config.SetCurrentContextName(context.Name)
8990
output.InfofWithHintExamples([][]string{
91+
{"Open in Azure Data Studio", "sqlcmd open ads"},
9092
{"To start interactive query session", "sqlcmd query"},
9193
{"To run a query", "sqlcmd query \"SELECT @@version\""},
9294
}, "Current Context '%v'", context.Name)

0 commit comments

Comments
 (0)