Skip to content
Open
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
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
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
7,167 changes: 3,582 additions & 3,585 deletions internal/translations/catalog.go

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions internal/translations/locales/de-DE/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "Konfigurationsdatei",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
6 changes: 3 additions & 3 deletions internal/translations/locales/en-US/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "configuration file",
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": "YAML configuration file (.yaml or .yml extension)",
"translatorComment": "Copied from source.",
"fuzzy": true
},
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/es-ES/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "archivo de configuración",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/fr-FR/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "fichier de configuration",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/it-IT/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "file di configurazione",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/ja-JP/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "構成ファイル",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/ko-KR/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "구성 파일",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/pt-BR/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "Arquivo de configuração:",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/ru-RU/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "файл конфигурации:",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/zh-CN/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "配置文件",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
8 changes: 3 additions & 5 deletions internal/translations/locales/zh-TW/out.gotext.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@
"fuzzy": true
},
{
"id": "configuration file",
"message": "configuration file",
"translation": "設定檔",
"translatorComment": "Copied from source.",
"fuzzy": true
"id": "YAML configuration file (.yaml or .yml extension)",
"message": "YAML configuration file (.yaml or .yml extension)",
"translation": ""
},
{
"id": "log level, error=0, warn=1, info=2, debug=3, trace=4",
Expand Down
Loading