Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
contents: write
pull-requests: write
steps:
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
- uses: googleapis/release-please-action@5c625bfb5d1ff62eadeeb3772007f7f66fdcf071 # v4.4.1
with:
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ sqlcmd config connection-strings
sqlcmd config view
```

#### Custom Configuration Files

The `--sqlconfig` flag specifies a custom configuration file. Files must be **YAML format** with a `.yaml` or `.yml` extension:

```
sqlcmd config --sqlconfig ./myproject.yaml add-endpoint --name ep1434 --address localhost --port 1434
sqlcmd config --sqlconfig ./myproject.yaml view
```

The default file (`~/.sqlcmd/sqlconfig`) has no extension but is also YAML.

### Versions

To see all version tags to choose from (2017, 2019, 2022 etc.), and install a specific version, run:
Expand Down
2 changes: 1 addition & 1 deletion cmd/modern/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c *Root) addGlobalFlags() {
String: &c.configFilename,
DefaultString: config.DefaultFileName(),
Name: "sqlconfig",
Usage: localizer.Sprintf("configuration file"),
Usage: localizer.Sprintf("YAML configuration file (.yaml or .yml extension)"),
})

/* BUG(stuartpa): - At the moment this is a top level flag, but it doesn't
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/golang-sql/sqlexp v0.1.0
github.com/google/uuid v1.6.0
github.com/microsoft/go-mssqldb v1.9.8
github.com/moby/moby/api v1.54.2
github.com/moby/moby/client v0.4.1
github.com/moby/moby/api v1.54.1
github.com/moby/moby/client v0.4.0
github.com/opencontainers/image-spec v1.1.1
github.com/peterh/liner v1.2.2
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -40,7 +40,7 @@ require (
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
github.com/docker/go-connections v0.7.0 // indirect
github.com/docker/go-connections v0.6.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZ
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/go-connections v0.7.0 h1:6SsRfJddP22WMrCkj19x9WKjEDTB+ahsdiGYf0mN39c=
github.com/docker/go-connections v0.7.0/go.mod h1:no1qkHdjq7kLMGUXYAduOhYPSJxxvgWBh7ogVvptn3Q=
github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94=
github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE=
github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8=
github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHzueweSI3Vw=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
Expand Down Expand Up @@ -117,10 +117,10 @@ github.com/microsoft/go-mssqldb v1.9.8 h1:d4IFMvF/o+HdpXUqbBfzHvn/NlFA75YGcfHUUv
github.com/microsoft/go-mssqldb v1.9.8/go.mod h1:eGSRSGAW4hKMy5YcAenhCDjIRm2rhqIdmmwgciMzLus=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/moby/api v1.54.2 h1:wiat9QAhnDQjA7wk1kh/TqHz2I1uUA7M7t9SAl/JNXg=
github.com/moby/moby/api v1.54.2/go.mod h1:+RQ6wluLwtYaTd1WnPLykIDPekkuyD/ROWQClE83pzs=
github.com/moby/moby/client v0.4.1 h1:DMQgisVoMkmMs7fp3ROSdiBnoAu8+vo3GggFl06M/wY=
github.com/moby/moby/client v0.4.1/go.mod h1:z52C9O2POPOsnxZAy//WtKcQ32P+jT/NGeXu/7nfjGQ=
github.com/moby/moby/api v1.54.1 h1:TqVzuJkOLsgLDDwNLmYqACUuTehOHRGKiPhvH8V3Nn4=
github.com/moby/moby/api v1.54.1/go.mod h1:+RQ6wluLwtYaTd1WnPLykIDPekkuyD/ROWQClE83pzs=
github.com/moby/moby/client v0.4.0 h1:S+2XegzHQrrvTCvF6s5HFzcrywWQmuVnhOXe2kiWjIw=
github.com/moby/moby/client v0.4.0/go.mod h1:QWPbvWchQbxBNdaLSpoKpCdf5E+WxFAgNHogCWDoa7g=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
Expand Down
17 changes: 14 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
package config

import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

. "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
"github.com/microsoft/go-sqlcmd/internal/io/file"
"github.com/microsoft/go-sqlcmd/internal/io/folder"
"github.com/microsoft/go-sqlcmd/internal/pal"
"os"
"path/filepath"
"testing"
)

var config Sqlconfig
Expand All @@ -24,6 +27,14 @@ func SetFileName(name string) {
panic("name is empty")
}

ext := strings.ToLower(filepath.Ext(name))
if ext != "" && ext != ".yaml" && ext != ".yml" {
checkErr(fmt.Errorf(
"configuration file %q has unsupported extension %q (must be .yaml or .yml)",
name, ext))
return
}

filename = name

file.CreateEmptyIfNotExists(filename)
Expand Down
16 changes: 12 additions & 4 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
package config

import (
"os"
"reflect"
"strings"
"testing"

. "github.com/microsoft/go-sqlcmd/cmd/modern/sqlconfig"
"github.com/microsoft/go-sqlcmd/internal/output"
"github.com/microsoft/go-sqlcmd/internal/pal"
"github.com/microsoft/go-sqlcmd/internal/secret"
"github.com/stretchr/testify/assert"
"os"
"reflect"
"strings"
"testing"
)

func TestConfig(t *testing.T) {
Expand Down Expand Up @@ -392,6 +393,13 @@ func TestNegConfig_SetFileName(t *testing.T) {
})
}

func TestNegConfig_SetFileNameBadExtension(t *testing.T) {
assert.Panics(t, func() { SetFileName("foo.json") })
assert.Panics(t, func() { SetFileName("config.toml") })
assert.NotPanics(t, func() { SetFileName(pal.FilenameInUserHomeDotDirectory(".sqlcmd", "sqlconfig-test-yaml.yaml")) })
assert.NotPanics(t, func() { SetFileName(pal.FilenameInUserHomeDotDirectory(".sqlcmd", "sqlconfig-test-yml.yml")) })
}

func TestNegConfig_SetCurrentContextName(t *testing.T) {
assert.Panics(t, func() {
SetCurrentContextName("does not exist")
Expand Down
Loading
Loading