Skip to content

Commit e83be44

Browse files
authored
Merge pull request #380 from DannyBen/feature/add-settings-schema
Feature: schema for settings.yml
2 parents 8013503 + 3a6f8d8 commit e83be44

File tree

4 files changed

+166
-6
lines changed

4 files changed

+166
-6
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,7 @@ jobs:
7171
run: bundle exec run shellcheck
7272
- name: Run shfmt tests
7373
run: bundle exec run shfmt
74-
- name: Run schema tests
75-
run: bundle exec run schema
74+
- name: Run bashly schema tests
75+
run: bundle exec run schema examples
76+
- name: Run settings schema tests
77+
run: bundle exec run schema settings
File renamed without changes.

schemas/settings.json

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema",
3+
"definitions": {
4+
"color": {
5+
"oneOf": [
6+
{
7+
"type": "string",
8+
"examples": [
9+
"red",
10+
"green",
11+
"yellow",
12+
"blue",
13+
"magenta",
14+
"cyan",
15+
"bold",
16+
"underlined",
17+
"red_bold",
18+
"green_bold",
19+
"yellow_bold",
20+
"blue_bold",
21+
"magenta_bold",
22+
"cyan_bold",
23+
"red_underlined",
24+
"green_underlined",
25+
"yellow_underlined",
26+
"blue_underlined",
27+
"magenta_underlined",
28+
"cyan_underlined"
29+
]
30+
},
31+
{
32+
"type": "null"
33+
}
34+
]
35+
}
36+
},
37+
"title": "settings",
38+
"description": "Settings of the current application",
39+
"type": "object",
40+
"properties": {
41+
"source_dir": {
42+
"title": "source dir",
43+
"description": "A directory with source files of the current script",
44+
"type": "string",
45+
"minLength": 1,
46+
"default": "src"
47+
},
48+
"config_path": {
49+
"title": "config path",
50+
"description": "A path to bashly.yml of the current script",
51+
"type": "string",
52+
"minLength": 1,
53+
"default": "%{source_dir}/bashly.yml"
54+
},
55+
"target_dir": {
56+
"title": "target dir",
57+
"description": "A directory of the current script",
58+
"type": "string",
59+
"minLength": 1,
60+
"default": "."
61+
},
62+
"lib_dir": {
63+
"title": "lib dir",
64+
"description": "A directory to common library files of the current script",
65+
"type": "string",
66+
"minLength": 1,
67+
"default": "lib"
68+
},
69+
"strict": {
70+
"title": "strict",
71+
"description": "Bash initialiation options of the current script",
72+
"oneOf": [
73+
{
74+
"type": "boolean"
75+
},
76+
{
77+
"type": "string",
78+
"examples": [
79+
"set -o pipefail"
80+
]
81+
}
82+
],
83+
"default": false
84+
},
85+
"tab_indent": {
86+
"title": "tab indent",
87+
"description": "Whether to use tabs in the the current script",
88+
"type": "boolean",
89+
"default": false
90+
},
91+
"compact_short_flags": {
92+
"title": "compact short flags",
93+
"description": "Whether to expand short flags of the current script",
94+
"type": "boolean",
95+
"default": true
96+
},
97+
"env": {
98+
"title": "env",
99+
"description": "Whether to include development related comments in the current script",
100+
"type": "string",
101+
"enum": [
102+
"development",
103+
"production"
104+
],
105+
"default": "development"
106+
},
107+
"partials_extension": {
108+
"title": "partials extension",
109+
"description": "A partial snippet extension of the current script",
110+
"type": "string",
111+
"minLength": 1,
112+
"default": "sh"
113+
},
114+
"usage_colors": {
115+
"title": "usage colors",
116+
"description": "Usage colors of the current script",
117+
"type": "object",
118+
"properties": {
119+
"caption": {
120+
"title": "caption",
121+
"description": "A caption color of the current script",
122+
"$ref": "#/definitions/color"
123+
},
124+
"command": {
125+
"title": "command",
126+
"description": "A command color of the current script",
127+
"$ref": "#/definitions/color"
128+
},
129+
"arg": {
130+
"title": "arg",
131+
"description": "An argument color of the current script",
132+
"$ref": "#/definitions/color"
133+
},
134+
"flag": {
135+
"title": "flag",
136+
"description": "A flag color of the current script",
137+
"$ref": "#/definitions/color"
138+
},
139+
"environment_variable": {
140+
"title": "environment variable",
141+
"description": "An environment variable color of the current script",
142+
"$ref": "#/definitions/color"
143+
}
144+
},
145+
"additionalProperties": false
146+
}
147+
},
148+
"additionalProperties": false
149+
}

support/runfile/schema.runfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
summary 'Run json-schema checks on all examples'
22

3-
action do
3+
help 'Test the bashly schema against all examples'
4+
action :examples do
45
Example.all.each do |example|
56
file = example.yaml_path
6-
command = "check-jsonschema --schemafile schema.json #{file}"
7+
command = "check-jsonschema --schemafile schemas/bashly.json #{file}"
8+
say "\n$ check-jsonschema bb`#{example.dir}`"
79
success = system command
8-
color = success ? 'g' : 'r'
9-
say "- check-jsonschema #{color}`#{example.dir}`"
1010
exit 1 unless success
1111
end
1212
end
13+
14+
help 'Test the settings schema against the default settings template'
15+
action :settings do
16+
file = 'lib/bashly/libraries/settings/settings.yml'
17+
command = "check-jsonschema --schemafile schemas/settings.json #{file}"
18+
say "\n$ check-jsonschema bb`#{file}`"
19+
success = system command
20+
exit 1 unless success
21+
end

0 commit comments

Comments
 (0)