Skip to content
Draft
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
12 changes: 12 additions & 0 deletions docs/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ The only input for this command is the `--in=<folderPath>` flag, which is used t

The output of this command is the resulting config YAML, which is written to STDOUT. If `--out=<filePath>` is specified, the output is written to the specified file instead.

### .yamltectureignore

A `.yamltectureignore` file can be placed in the folder to exclude specific YAML files from being merged. This file uses the same syntax as `.gitignore` files. Each line in the file specifies a pattern for files to ignore.

For example, to ignore a file named `example.yaml`, add the following line to `.yamltectureignore`:

```
example.yaml
```

The `.yamltectureignore` file supports standard gitignore patterns including wildcards, negation with `!`, and comments with `#`.

## Execute Query

The execute query command, `--executeQuery`, takes in both a configuration file and a query file. The validate config and validate query checks are always performed, but the details as for the failure of these checks are not displayed.
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/UnitVectorY-Labs/yamlequal v0.0.3
github.com/go-playground/validator/v10 v10.30.1
github.com/google/uuid v1.6.0
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
golang.org/x/term v0.39.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
github.com/UnitVectorY-Labs/yamlequal v0.0.3 h1:RV49y9wQ9eqrkIJ0Wf3o8+jNN3BT/5QA40/1tAmRYp4=
github.com/UnitVectorY-Labs/yamlequal v0.0.3/go.mod h1:CTx9pQWdA+OANe7a7f0QIex580Y8T6pR3Hh/X8dcL2g=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=
Expand All @@ -18,6 +19,10 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 h1:OkMGxebDjyw0ULyrTYWeN0UNCCkmCWfjPnIA2W6oviI=
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06/go.mod h1:+ePHsJ1keEjQtpvf9HHw0f4ZeJ0TLRsxhunSI2hYJSs=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
Expand All @@ -30,5 +35,6 @@ golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 15 additions & 0 deletions internal/configuration/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"

"github.com/google/uuid"
ignore "github.com/sabhiram/go-gitignore"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -41,6 +42,16 @@ func LoadFolder(folderPath string) (*Config, error) {
return nil, fmt.Errorf("folderPath is not a directory")
}

// Check for .yamltectureignore file
var ignorer *ignore.GitIgnore
ignorePath := filepath.Join(folderPath, ".yamltectureignore")
if _, err := os.Stat(ignorePath); err == nil {
ignorer, err = ignore.CompileIgnoreFile(ignorePath)
if err != nil {
return nil, fmt.Errorf("error parsing .yamltectureignore: %v", err)
}
}

// Loop through the folder contents loading in all .yaml files with LoadConfig
configs := []*Config{}
files, err := os.ReadDir(folderPath)
Expand All @@ -52,6 +63,10 @@ func LoadFolder(folderPath string) (*Config, error) {
continue
}
if filepath.Ext(file.Name()) == ".yaml" {
// Check if the file should be ignored
if ignorer != nil && ignorer.MatchesPath(file.Name()) {
continue
}
config, err := LoadConfig(filepath.Join(folderPath, file.Name()))
if err != nil {
return nil, fmt.Errorf("error loading config file: %v", err)
Expand Down
6 changes: 6 additions & 0 deletions tests/ignore/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
nodes:
- id: node_included
type: Application
attributes:
name: Included Node
links: []
2 changes: 2 additions & 0 deletions tests/ignore/configs/.yamltectureignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore the ignored.yaml file
ignored.yaml
7 changes: 7 additions & 0 deletions tests/ignore/configs/ignored.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodes:
- id: node_ignored
type: Application
attributes:
name: "Ignored Node"

links:
7 changes: 7 additions & 0 deletions tests/ignore/configs/included.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodes:
- id: node_included
type: Application
attributes:
name: "Included Node"

links: