Skip to content

Commit 96bb9dd

Browse files
author
yakwilikk
authored
Merge pull request #203 from easyp-tech/feature/config-validation2
## Что сделано Добавлена команда `validate-config` (алиас: `validate`) для отдельной валидации `easyp.yaml` без запуска `lint/generate`. Основные изменения: - Добавлен CLI-хендлер `validate-config`. - Реализована schema-валидация конфига через `go-yamlvalidator`. - Добавлена классификация проблем по severity: - `error` — блокирующие ошибки - `warn` — предупреждения (например, unknown keys) - Добавлен вывод в двух форматах: - `json` (по умолчанию) - `text` - Поддержан глобальный флаг `--format` для команды. - Обновлена документация (`README`, EN/RU guide по configuration). ## Поведение команды - По умолчанию проверяется `easyp.yaml` (можно передать путь через `--config`/`-c`). - Перед валидацией разворачиваются переменные окружения в конфиге. - Команда возвращает: - `exit code 0`, если есть только warnings или проблем нет - `non-zero`, если есть ошибки валидации - В выводе ошибки и предупреждения разделяются. ## Примеры ```bash # Проверка конфига по умолчанию (JSON) easyp validate-config # Проверка конкретного файла в текстовом виде easyp validate-config --config example.easyp.yaml --format text
2 parents e7eb4cc + 5f9f1a3 commit 96bb9dd

18 files changed

Lines changed: 727 additions & 58 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ easyp.lock
88
.DS_Store
99
node_modules
1010
*.tsbuildinfo
11+
.rules-mcp

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ For comprehensive usage information, consult EasyP's [documentation](https://eas
7575
* [`easyp breaking`](https://easyp.tech/docs/guide/cli/breaking-changes/breaking-changes) - Breaking change detection
7676
* [`easyp mod`](https://easyp.tech/docs/guide/cli/package-manager/package-manager) - Package management
7777
* [`easyp generate`](https://easyp.tech/docs/guide/cli/generator/generator) - Code generation
78+
* `easyp validate-config` - Validate `easyp.yaml` structure and types (JSON or text output)
79+
* Global flag: `--format, -f` / env `EASYP_FORMAT` (`text` or `json`) for commands that support formatted output
7880

7981
## Key Features
8082

@@ -139,6 +141,18 @@ lint:
139141
- PACKAGE_DEFINED
140142
- FIELD_LOWER_SNAKE_CASE
141143
- MESSAGE_PASCAL_CASE
144+
145+
# Configuration validation
146+
147+
`easyp validate-config` validates `easyp.yaml` (or a custom path passed via `--config`). It expands env vars, checks required fields and types, warns on unknown keys, and exits with a non-zero status when errors are found.
148+
149+
```sh
150+
# Validate the default easyp.yaml with JSON output (default)
151+
easyp validate-config
152+
153+
# Validate a custom file with text output
154+
easyp validate-config --config example.easyp.yaml --format text
155+
```
142156
```
143157

144158
## Community

cmd/easyp/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ func main() {
4949
api.Init{},
5050
api.Generate{},
5151
api.LsFiles{},
52+
api.Validate{},
5253
api.BreakingCheck{},
5354
),
5455
Flags: []cli.Flag{
5556
flags.Config,
5657
flags.DebugMode,
58+
flags.Format,
5759
},
5860
Before: func(ctx *cli.Context) error {
5961
log := initLogger(ctx.Bool(flags.DebugMode.Name))

docs/dist/docs/guide/cli/configuration/configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ easyp init
117117
easyp init --dir proto-project/
118118
```
119119

120+
**Validate-config command:**
121+
```bash
122+
easyp validate-config [flags]
123+
```
124+
125+
| Flag | Short | Environment | Description | Default |
126+
|------|-------|-------------|-------------|---------|
127+
| `--config` | `-c` | `EASYP_CFG` | Configuration file path | `easyp.yaml` |
128+
| `--format` | `-f` | | Output format (`json` or `text`) | `json` |
129+
130+
**Examples:**
131+
```bash
132+
# Validate default config with JSON output (exit 0 when no errors)
133+
easyp validate-config
134+
135+
# Validate a different file with text output
136+
easyp validate-config --config example.easyp.yaml --format text
137+
```
138+
120139
**Package management commands:**
121140

122141
#### `easyp mod download`

docs/dist/docs/ru-guide/cli/configuration/configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ easyp init
117117
easyp init --dir proto-project/
118118
```
119119

120+
**Validate-config command:**
121+
```bash
122+
easyp validate-config [flags]
123+
```
124+
125+
| Flag | Short | Environment | Description | Default |
126+
|------|-------|-------------|-------------|---------|
127+
| `--config` | `-c` | `EASYP_CFG` | Путь до файла конфигурации | `easyp.yaml` |
128+
| `--format` | `-f` | | Формат вывода (`json` или `text`) | `json` |
129+
130+
**Examples:**
131+
```bash
132+
# Проверить конфиг по умолчанию с JSON выводом (статус 0 если ошибок нет)
133+
easyp validate-config
134+
135+
# Проверить другой файл и вывести в текстовом формате
136+
easyp validate-config --config example.easyp.yaml --format text
137+
```
138+
120139
**Package management commands:**
121140

122141
#### `easyp mod download`

docs/public/docs/guide/cli/configuration/configuration.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Available for all commands:
1313
| `--cfg` | `-c` | `EASYP_CFG` | Configuration file path | `easyp.yaml` |
1414
| `--config` | | `EASYP_CFG` | Alias for `--cfg` | `easyp.yaml` |
1515
| `--debug` | `-d` | `EASYP_DEBUG` | Enable debug mode | `false` |
16+
| `--format` | `-f` | `EASYP_FORMAT` | Output format for commands that support multiple formats (`text`/`json`) | command-specific default |
1617

1718
**Examples:**
1819
```bash
@@ -37,7 +38,7 @@ easyp lint [flags]
3738
|------|-------|-------------|-------------|---------|
3839
| `--path` | `-p` | | Directory path to lint | `.` |
3940
| `--root` | `-r` | | Base directory for file search | Current working directory |
40-
| `--format` | `-f` | `EASYP_FORMAT` | Output format (text/json) | `text` |
41+
| `--format` | `-f` | `EASYP_FORMAT` | Uses global format flag (`text`/`json`) | Inherits global default |
4142

4243
**Examples:**
4344
```bash
@@ -48,7 +49,7 @@ easyp lint --path proto/
4849
easyp lint --root src/IPC/Contracts --path .
4950

5051
# JSON output format
51-
easyp lint --format json
52+
easyp lint --format json # global flag
5253

5354
# Combined flags
5455
easyp lint -p proto/ -f json
@@ -85,7 +86,7 @@ easyp breaking [flags]
8586
|------|-------|-------------|-------------|---------|
8687
| `--against` | | | Git ref to compare against | (required) |
8788
| `--path` | `-p` | | Directory path to check | `.` |
88-
| `--format` | `-f` | `EASYP_FORMAT` | Output format (text/json) | `text` |
89+
| `--format` | `-f` | `EASYP_FORMAT` | Uses global format flag (`text`/`json`) | Inherits global default |
8990

9091
**Examples:**
9192
```bash
@@ -96,7 +97,7 @@ easyp breaking --against main
9697
easyp breaking --against develop --path proto/
9798

9899
# JSON output
99-
easyp breaking --against main --format json
100+
easyp breaking --against main --format json # global flag
100101
```
101102

102103
**Init command:**
@@ -117,6 +118,25 @@ easyp init
117118
easyp init --dir proto-project/
118119
```
119120

121+
**Validate-config command:**
122+
```bash
123+
easyp validate-config [flags]
124+
```
125+
126+
| Flag | Short | Environment | Description | Default |
127+
|------|-------|-------------|-------------|---------|
128+
| `--config` | `-c` | `EASYP_CFG` | Configuration file path | `easyp.yaml` |
129+
| `--format` | `-f` | | Output format (`json` or `text`) | `json` |
130+
131+
**Examples:**
132+
```bash
133+
# Validate default config with JSON output (exit 0 when no errors)
134+
easyp validate-config
135+
136+
# Validate a different file with text output
137+
easyp validate-config --config example.easyp.yaml --format text
138+
```
139+
120140
**Package management commands:**
121141

122142
#### `easyp mod download`
@@ -161,7 +181,7 @@ EasyP supports environment variables for configuration:
161181
| `EASYP_CFG` | Path to configuration file | `easyp.yaml` |
162182
| `EASYP_DEBUG` | Enable debug logging | `false` |
163183
| `EASYPPATH` | Cache and modules storage directory | `$HOME/.easyp` |
164-
| `EASYP_FORMAT` | Output format for lint command | `text` |
184+
| `EASYP_FORMAT` | Output format for supported commands (`text`/`json`). If not set, each command uses its own default. | command-specific default |
165185
| `EASYP_ROOT_GENERATE_PATH` | Root path for generate command | `.` |
166186
| `EASYP_INIT_DIR` | Directory for init command | `.` |
167187

docs/public/docs/ru-guide/cli/configuration/configuration.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Available for all commands:
1313
| `--cfg` | `-c` | `EASYP_CFG` | Configuration file path | `easyp.yaml` |
1414
| `--config` | | `EASYP_CFG` | Alias for `--cfg` | `easyp.yaml` |
1515
| `--debug` | `-d` | `EASYP_DEBUG` | Enable debug mode | `false` |
16+
| `--format` | `-f` | `EASYP_FORMAT` | Формат вывода для команд с поддержкой нескольких форматов (`text`/`json`) | значение по умолчанию зависит от команды |
1617

1718
**Examples:**
1819
```bash
@@ -37,7 +38,7 @@ easyp lint [flags]
3738
|------|-------|-------------|-------------|---------|
3839
| `--path` | `-p` | | Directory path to lint | `.` |
3940
| `--root` | `-r` | | Базовая директория для поиска файлов | Текущая рабочая директория |
40-
| `--format` | `-f` | `EASYP_FORMAT` | Output format (text/json) | `text` |
41+
| `--format` | `-f` | `EASYP_FORMAT` | Использует глобальный флаг формата (`text`/`json`) | Использует глобальное значение по умолчанию |
4142

4243
**Examples:**
4344
```bash
@@ -48,7 +49,7 @@ easyp lint --path proto/
4849
easyp lint --root src/IPC/Contracts --path .
4950

5051
# JSON output format
51-
easyp lint --format json
52+
easyp lint --format json # глобальный флаг
5253

5354
# Combined flags
5455
easyp lint -p proto/ -f json
@@ -85,7 +86,7 @@ easyp breaking [flags]
8586
|------|-------|-------------|-------------|---------|
8687
| `--against` | | | Git ref to compare against | (required) |
8788
| `--path` | `-p` | | Directory path to check | `.` |
88-
| `--format` | `-f` | `EASYP_FORMAT` | Output format (text/json) | `text` |
89+
| `--format` | `-f` | `EASYP_FORMAT` | Использует глобальный флаг формата (`text`/`json`) | Использует глобальное значение по умолчанию |
8990

9091
**Examples:**
9192
```bash
@@ -96,7 +97,7 @@ easyp breaking --against main
9697
easyp breaking --against develop --path proto/
9798

9899
# JSON output
99-
easyp breaking --against main --format json
100+
easyp breaking --against main --format json # глобальный флаг
100101
```
101102

102103
**Init command:**
@@ -117,6 +118,25 @@ easyp init
117118
easyp init --dir proto-project/
118119
```
119120

121+
**Validate-config command:**
122+
```bash
123+
easyp validate-config [flags]
124+
```
125+
126+
| Flag | Short | Environment | Description | Default |
127+
|------|-------|-------------|-------------|---------|
128+
| `--config` | `-c` | `EASYP_CFG` | Путь до файла конфигурации | `easyp.yaml` |
129+
| `--format` | `-f` | | Формат вывода (`json` или `text`) | `json` |
130+
131+
**Examples:**
132+
```bash
133+
# Проверить конфиг по умолчанию с JSON выводом (статус 0 если ошибок нет)
134+
easyp validate-config
135+
136+
# Проверить другой файл и вывести в текстовом формате
137+
easyp validate-config --config example.easyp.yaml --format text
138+
```
139+
120140
**Package management commands:**
121141

122142
#### `easyp mod download`
@@ -161,7 +181,7 @@ EasyP supports environment variables for configuration:
161181
| `EASYP_CFG` | Path to configuration file | `easyp.yaml` |
162182
| `EASYP_DEBUG` | Enable debug logging | `false` |
163183
| `EASYPPATH` | Cache and modules storage directory | `$HOME/.easyp` |
164-
| `EASYP_FORMAT` | Output format for lint command | `text` |
184+
| `EASYP_FORMAT` | Формат вывода для поддерживаемых команд (`text`/`json`). Если не указан, каждая команда использует своё значение по умолчанию. | значение по умолчанию зависит от команды |
165185
| `EASYP_ROOT_GENERATE_PATH` | Root path for generate command | `.` |
166186
| `EASYP_INIT_DIR` | Directory for init command | `.` |
167187

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/easyp-tech/easyp
33
go 1.24.0
44

55
require (
6+
github.com/a8m/envsubst v1.4.3
67
github.com/brianvoe/gofakeit/v6 v6.28.0
78
github.com/bufbuild/protocompile v0.14.1
89
github.com/codeclysm/extract/v3 v3.1.1
@@ -14,6 +15,7 @@ require (
1415
github.com/tetratelabs/wazero v1.9.0
1516
github.com/urfave/cli/v2 v2.27.7
1617
github.com/wasilibs/wazero-helpers v0.0.0-20250123031827-cd30c44769bb
18+
github.com/yakwilikk/go-yamlvalidator v0.0.0-20260216223344-568790865548
1719
github.com/yoheimuta/go-protoparser/v4 v4.14.2
1820
golang.org/x/mod v0.30.0
1921
google.golang.org/grpc v1.76.0
@@ -25,7 +27,6 @@ require (
2527
dario.cat/mergo v1.0.2 // indirect
2628
github.com/Microsoft/go-winio v0.6.2 // indirect
2729
github.com/ProtonMail/go-crypto v1.3.0 // indirect
28-
github.com/a8m/envsubst v1.4.3 // indirect
2930
github.com/cloudflare/circl v1.6.1 // indirect
3031
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
3132
github.com/cyphar/filepath-securejoin v0.6.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM
117117
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
118118
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
119119
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
120+
github.com/yakwilikk/go-yamlvalidator v0.0.0-20260216223344-568790865548 h1:wKohzDUpJJIQ+Tqbo1FvOsi/T3DNYOVceq6pXeGGh8o=
121+
github.com/yakwilikk/go-yamlvalidator v0.0.0-20260216223344-568790865548/go.mod h1:JIBeXFmTJyghm8crrAhNGhVxsNpCFSmuPLjz2spSBVU=
120122
github.com/yoheimuta/go-protoparser/v4 v4.14.2 h1:/P/LlX1CF9NaTWEltGcIZVvNlPbhABuAnBtAWpb3+74=
121123
github.com/yoheimuta/go-protoparser/v4 v4.14.2/go.mod h1:AHNNnSWnb0UoL4QgHPiOAg2BniQceFscPI5X/BZNHl8=
122124
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=

internal/api/breaking_check.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func (b BreakingCheck) Command() *cli.Command {
4848
Subcommands: nil,
4949
Flags: []cli.Flag{
5050
flagLintDirectoryPath,
51-
flagFormat,
5251
flagAgainstBranchName,
5352
},
5453
SkipFlagParsing: false,
@@ -118,7 +117,7 @@ func (b BreakingCheck) action(ctx *cli.Context, log logger.Logger) error {
118117
return nil
119118
}
120119

121-
format := ctx.String(flagFormat.Name)
120+
format := flags.GetFormat(ctx, flags.TextFormat)
122121
if err := printIssues(
123122
format,
124123
os.Stdout,

0 commit comments

Comments
 (0)