diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml index 8fb024f174..4ded0ee603 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.yml +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.yml @@ -51,7 +51,7 @@ body: id: config attributes: label: Configuration - description: Please include the sqlc.yaml or sqlc.json file you using in your project. This will be automatically formatted, so no need for backticks. + description: Please include the sqlc.(yaml|yml) or sqlc.json file you using in your project. This will be automatically formatted, so no need for backticks. render: yaml - type: input id: playground diff --git a/docs/reference/config.md b/docs/reference/config.md index d4a28db612..c0ba543503 100644 --- a/docs/reference/config.md +++ b/docs/reference/config.md @@ -1,6 +1,6 @@ # Configuration -The `sqlc` tool is configured via a `sqlc.yaml` or `sqlc.json` file. This +The `sqlc` tool is configured via a `sqlc.(yaml|yml)` or `sqlc.json` file. This file must be in the directory where the `sqlc` command is run. ## Version 2 diff --git a/docs/tutorials/getting-started-mysql.md b/docs/tutorials/getting-started-mysql.md index 2f86a7bd39..4fa55d713c 100644 --- a/docs/tutorials/getting-started-mysql.md +++ b/docs/tutorials/getting-started-mysql.md @@ -11,7 +11,7 @@ Initialize a new Go module named `tutorial.sql.dev/app` go mod init tutorial.sqlc.dev/app ``` -sqlc looks for either a `sqlc.yaml` or `sqlc.json` file in the current +sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: diff --git a/docs/tutorials/getting-started-postgresql.md b/docs/tutorials/getting-started-postgresql.md index bc761be004..9f7d09a1a4 100644 --- a/docs/tutorials/getting-started-postgresql.md +++ b/docs/tutorials/getting-started-postgresql.md @@ -1,4 +1,4 @@ -# Getting started with PostgreSQL +# Getting started with PostgreSQL This tutorial assumes that the latest version of sqlc is [installed](../overview/install.md) and ready to use. @@ -11,7 +11,7 @@ Initialize a new Go module named `tutorial.sqlc.dev/app` go mod init tutorial.sqlc.dev/app ``` -sqlc looks for either a `sqlc.yaml` or `sqlc.json` file in the current +sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: diff --git a/docs/tutorials/getting-started-sqlite.md b/docs/tutorials/getting-started-sqlite.md index 96bb693e23..28f0669ea3 100644 --- a/docs/tutorials/getting-started-sqlite.md +++ b/docs/tutorials/getting-started-sqlite.md @@ -11,7 +11,7 @@ Initialize a new Go module named `tutorial.sql.dev/app` go mod init tutorial.sqlc.dev/app ``` -sqlc looks for either a `sqlc.yaml` or `sqlc.json` file in the current +sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current directory. In our new directory, create a file named `sqlc.yaml` with the following contents: diff --git a/internal/cmd/generate.go b/internal/cmd/generate.go index b479670e5d..1e1e6e54cd 100644 --- a/internal/cmd/generate.go +++ b/internal/cmd/generate.go @@ -76,8 +76,9 @@ func readConfig(stderr io.Writer, dir, filename string) (string, *config.Config, if filename != "" { configPath = filepath.Join(dir, filename) } else { - var yamlMissing, jsonMissing bool + var yamlMissing, jsonMissing, ymlMissing bool yamlPath := filepath.Join(dir, "sqlc.yaml") + ymlPath := filepath.Join(dir, "sqlc.yml") jsonPath := filepath.Join(dir, "sqlc.json") if _, err := os.Stat(yamlPath); os.IsNotExist(err) { @@ -87,18 +88,27 @@ func readConfig(stderr io.Writer, dir, filename string) (string, *config.Config, jsonMissing = true } - if yamlMissing && jsonMissing { - fmt.Fprintln(stderr, "error parsing configuration files. sqlc.yaml or sqlc.json: file does not exist") + if _, err := os.Stat(ymlPath); os.IsNotExist(err) { + ymlMissing = true + } + + if yamlMissing && ymlMissing && jsonMissing { + fmt.Fprintln(stderr, "error parsing configuration files. sqlc.(yaml|yml) or sqlc.json: file does not exist") return "", nil, errors.New("config file missing") } - if !yamlMissing && !jsonMissing { - fmt.Fprintln(stderr, "error: both sqlc.json and sqlc.yaml files present") - return "", nil, errors.New("sqlc.json and sqlc.yaml present") + if (!yamlMissing || !ymlMissing) && !jsonMissing { + fmt.Fprintln(stderr, "error: both sqlc.json and sqlc.(yaml|yml) files present") + return "", nil, errors.New("sqlc.json and sqlc.(yaml|yml) present") } - configPath = yamlPath - if yamlMissing { + if jsonMissing { + if yamlMissing { + configPath = ymlPath + } else { + configPath = yamlPath + } + } else { configPath = jsonPath } } diff --git a/internal/endtoend/ddl_test.go b/internal/endtoend/ddl_test.go index 39aaa0292e..2ead5841c8 100644 --- a/internal/endtoend/ddl_test.go +++ b/internal/endtoend/ddl_test.go @@ -39,7 +39,7 @@ func TestValidSchema(t *testing.T) { if err != nil { return err } - if filepath.Base(path) == "sqlc.json" || filepath.Base(path) == "sqlc.yaml" { + if filepath.Base(path) == "sqlc.json" || filepath.Base(path) == "sqlc.yaml" || filepath.Base(path) == "sqlc.yml" { stderr := filepath.Join(filepath.Dir(path), "stderr.txt") if _, err := os.Stat(stderr); !os.IsNotExist(err) { return nil diff --git a/internal/endtoend/endtoend_test.go b/internal/endtoend/endtoend_test.go index e91e9f9c56..236b37d7ad 100644 --- a/internal/endtoend/endtoend_test.go +++ b/internal/endtoend/endtoend_test.go @@ -86,7 +86,7 @@ func TestReplay(t *testing.T) { if err != nil { return err } - if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" { + if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" || info.Name() == "sqlc.yml" { dirs = append(dirs, filepath.Dir(path)) return filepath.SkipDir } @@ -251,7 +251,7 @@ func BenchmarkReplay(b *testing.B) { if err != nil { return err } - if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" { + if info.Name() == "sqlc.json" || info.Name() == "sqlc.yaml" || info.Name() == "sqlc.yml" { dirs = append(dirs, filepath.Dir(path)) return filepath.SkipDir } diff --git a/scripts/regenerate/main.go b/scripts/regenerate/main.go index b2bcb2089f..c1a578b62d 100644 --- a/scripts/regenerate/main.go +++ b/scripts/regenerate/main.go @@ -39,7 +39,7 @@ func regenerate(dir string) error { if info.IsDir() { return nil } - if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") { + if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") || strings.HasSuffix(path, "sqlc.yml") { cwd := filepath.Dir(path) command, err := parseExecCommand(cwd) if err != nil {