Skip to content

Commit 2bcc8a3

Browse files
authored
Merge pull request #475 from DannyBen/add/specs
Add specs for `default_string` (`arg` and `flag`)
2 parents a96044c + 2c75ef0 commit 2bcc8a3

File tree

7 files changed

+151
-146
lines changed

7 files changed

+151
-146
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: bundle exec rspec
4848

4949
static_analysis:
50-
name: Static analysis of Example files
50+
name: Example files static analysis
5151

5252
runs-on: ubuntu-latest
5353

@@ -85,7 +85,7 @@ jobs:
8585
run: bundle exec run shfmt
8686

8787
json_schema:
88-
name: Validate JSON schemas
88+
name: JSON schemas validation
8989

9090
runs-on: ubuntu-latest
9191

schemas/bashly.json

Lines changed: 39 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,44 @@
281281
},
282282
"additionalProperties": false
283283
},
284+
"environment-variable": {
285+
"title": "environment variable",
286+
"description": "An environment variable of the current application\nhttps://bashly.dannyb.co/configuration/environment-variable/#environment-variable",
287+
"type": "object",
288+
"required": [
289+
"name"
290+
],
291+
"properties": {
292+
"name": {
293+
"$ref": "#/definitions/environment-variables-name-property"
294+
},
295+
"help": {
296+
"$ref": "#/definitions/environment-variables-help-property"
297+
},
298+
"private": {
299+
"$ref": "#/definitions/environment-variables-private-property"
300+
},
301+
"required": {
302+
"$ref": "#/definitions/environment-variables-required-property"
303+
},
304+
"allowed": {
305+
"$ref": "#/definitions/environment-variables-allowed-property"
306+
},
307+
"default": {
308+
"$ref": "#/definitions/environment-variables-default-property"
309+
}
310+
},
311+
"patternProperties": {
312+
"^x_.": {
313+
"title": "custom property",
314+
"description": "A custom property of any type",
315+
"examples": [
316+
"Anything"
317+
]
318+
}
319+
},
320+
"additionalProperties": false
321+
},
284322
"name-property": {
285323
"title": "name",
286324
"description": "A name of the current script or sub-command\nhttps://bashly.dannyb.co/configuration/command/#name",
@@ -442,97 +480,7 @@
442480
"type": "array",
443481
"uniqueItems": true,
444482
"items": {
445-
"title": "environment variable",
446-
"description": "An environment variable of the current application\nhttps://bashly.dannyb.co/configuration/environment-variable/#environment-variable",
447-
"type": "object",
448-
"required": [
449-
"name"
450-
],
451-
"properties": {
452-
"name": {
453-
"$ref": "#/definitions/environment-variables-name-property"
454-
},
455-
"help": {
456-
"$ref": "#/definitions/environment-variables-help-property"
457-
},
458-
"default": {
459-
"$ref": "#/definitions/environment-variables-default-property"
460-
},
461-
"private": {
462-
"$ref": "#/definitions/environment-variables-private-property"
463-
},
464-
"required": {
465-
"$ref": "#/definitions/environment-variables-required-property"
466-
},
467-
"allowed": {
468-
"$ref": "#/definitions/environment-variables-allowed-property"
469-
}
470-
},
471-
"if": {
472-
"properties": {
473-
"required": {
474-
"const": false
475-
}
476-
}
477-
},
478-
"then": {
479-
"properties": {
480-
"name": {
481-
"$ref": "#/definitions/environment-variables-name-property"
482-
},
483-
"help": {
484-
"$ref": "#/definitions/environment-variables-help-property"
485-
},
486-
"default": {
487-
"$ref": "#/definitions/environment-variables-default-property"
488-
},
489-
"private": {
490-
"$ref": "#/definitions/environment-variables-private-property"
491-
},
492-
"required": {
493-
"$ref": "#/definitions/environment-variables-required-property"
494-
},
495-
"allowed": {
496-
"$ref": "#/definitions/environment-variables-allowed-property"
497-
}
498-
},
499-
"patternProperties": {
500-
"^x_.": {
501-
"title": "custom property",
502-
"description": "A custom property of any type",
503-
"examples": [
504-
"Anything"
505-
]
506-
}
507-
},
508-
"additionalProperties": false
509-
},
510-
"else": {
511-
"properties": {
512-
"name": {
513-
"$ref": "#/definitions/environment-variables-name-property"
514-
},
515-
"help": {
516-
"$ref": "#/definitions/environment-variables-help-property"
517-
},
518-
"private": {
519-
"$ref": "#/definitions/environment-variables-private-property"
520-
},
521-
"required": {
522-
"$ref": "#/definitions/environment-variables-required-property"
523-
}
524-
},
525-
"patternProperties": {
526-
"^x_.": {
527-
"title": "custom property",
528-
"description": "A custom property of any type",
529-
"examples": [
530-
"Anything"
531-
]
532-
}
533-
},
534-
"additionalProperties": false
535-
}
483+
"$ref": "#/definitions/environment-variable"
536484
}
537485
},
538486
"examples-property": {

spec/bashly/script/argument_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,32 @@
66

77
let(:fixture) { :basic_argument }
88

9+
describe '#default_string' do
10+
context 'when default is an array' do
11+
let(:fixture) { :default_array }
12+
13+
it 'returns a shell-escaped string suitable to be shell array source' do
14+
expect(subject.default_string).to eq 'spaced\\ one two'
15+
end
16+
end
17+
18+
context 'when default is string and repeatable is false' do
19+
let(:fixture) { :default_string }
20+
21+
it 'returns it as is' do
22+
expect(subject.default_string).to eq 'spaced one'
23+
end
24+
end
25+
26+
context 'when default is string and repeatable is true' do
27+
let(:fixture) { :default_string_with_repeatable }
28+
29+
it 'returns a single string' do
30+
expect(subject.default_string).to eq 'spaced\\ one'
31+
end
32+
end
33+
end
34+
935
describe '#usage_string' do
1036
it 'returns a string suitable to be used as a usage pattern' do
1137
expect(subject.usage_string).to eq '[FILE]'

spec/bashly/script/flag_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@
3030
end
3131
end
3232

33+
describe '#default_string' do
34+
context 'when default is an array' do
35+
let(:fixture) { :default_array }
36+
37+
it 'returns a shell-escaped string suitable to be shell array source' do
38+
expect(subject.default_string).to eq 'spaced\\ one two'
39+
end
40+
end
41+
42+
context 'when default is string and repeatable is false' do
43+
let(:fixture) { :default_string }
44+
45+
it 'returns it as is' do
46+
expect(subject.default_string).to eq 'spaced one'
47+
end
48+
end
49+
50+
context 'when default is string and repeatable is true' do
51+
let(:fixture) { :default_string_with_repeatable }
52+
53+
it 'returns a single string' do
54+
expect(subject.default_string).to eq 'spaced\\ one'
55+
end
56+
end
57+
end
58+
3359
describe '#name' do
3460
context 'with both short and long options' do
3561
it 'returns the long option' do

spec/fixtures/script/arguments.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,18 @@
88
:repeatable:
99
name: file
1010
repeatable: true
11+
12+
:default_string:
13+
name: file
14+
repeatable: false
15+
default: spaced one
16+
17+
:default_array:
18+
name: file
19+
repeatable: true
20+
default: [spaced one, two]
21+
22+
:default_string_with_repeatable:
23+
name: file
24+
repeatable: true
25+
default: spaced one

spec/fixtures/script/flags.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,22 @@
2525
:completions_completions:
2626
long: --path
2727
short: -p
28-
completions: [<file>, README.md]
28+
completions: [<file>, README.md]
29+
30+
:default_string:
31+
long: --file
32+
arg: path
33+
repeatable: false
34+
default: spaced one
35+
36+
:default_array:
37+
long: --file
38+
arg: path
39+
repeatable: true
40+
default: [spaced one, two]
41+
42+
:default_string_with_repeatable:
43+
long: --file
44+
arg: path
45+
repeatable: true
46+
default: spaced one

support/schema/bashly.yml

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,29 @@ definitions:
245245
const: true
246246
patternProperties: *custom-properties
247247
additionalProperties: false
248+
environment-variable:
249+
title: environment variable
250+
description: |-
251+
An environment variable of the current application
252+
https://bashly.dannyb.co/configuration/environment-variable/#environment-variable
253+
type: object
254+
required:
255+
- name
256+
properties:
257+
name:
258+
$ref: '#/definitions/environment-variables-name-property'
259+
help:
260+
$ref: '#/definitions/environment-variables-help-property'
261+
private:
262+
$ref: '#/definitions/environment-variables-private-property'
263+
required:
264+
$ref: '#/definitions/environment-variables-required-property'
265+
allowed:
266+
$ref: '#/definitions/environment-variables-allowed-property'
267+
default:
268+
$ref: '#/definitions/environment-variables-default-property'
269+
patternProperties: *custom-properties
270+
additionalProperties: false
248271
name-property:
249272
title: name
250273
description: |-
@@ -399,58 +422,7 @@ definitions:
399422
type: array
400423
uniqueItems: true
401424
items:
402-
title: environment variable
403-
description: |-
404-
An environment variable of the current application
405-
https://bashly.dannyb.co/configuration/environment-variable/#environment-variable
406-
type: object
407-
required:
408-
- name
409-
properties:
410-
name:
411-
$ref: '#/definitions/environment-variables-name-property'
412-
help:
413-
$ref: '#/definitions/environment-variables-help-property'
414-
default:
415-
$ref: '#/definitions/environment-variables-default-property'
416-
private:
417-
$ref: '#/definitions/environment-variables-private-property'
418-
required:
419-
$ref: '#/definitions/environment-variables-required-property'
420-
allowed:
421-
$ref: '#/definitions/environment-variables-allowed-property'
422-
if:
423-
properties:
424-
required:
425-
const: false
426-
then:
427-
properties:
428-
name:
429-
$ref: '#/definitions/environment-variables-name-property'
430-
help:
431-
$ref: '#/definitions/environment-variables-help-property'
432-
default:
433-
$ref: '#/definitions/environment-variables-default-property'
434-
private:
435-
$ref: '#/definitions/environment-variables-private-property'
436-
required:
437-
$ref: '#/definitions/environment-variables-required-property'
438-
allowed:
439-
$ref: '#/definitions/environment-variables-allowed-property'
440-
patternProperties: *custom-properties
441-
additionalProperties: false
442-
else:
443-
properties:
444-
name:
445-
$ref: '#/definitions/environment-variables-name-property'
446-
help:
447-
$ref: '#/definitions/environment-variables-help-property'
448-
private:
449-
$ref: '#/definitions/environment-variables-private-property'
450-
required:
451-
$ref: '#/definitions/environment-variables-required-property'
452-
patternProperties: *custom-properties
453-
additionalProperties: false
425+
$ref: '#/definitions/environment-variable'
454426
examples-property:
455427
title: examples
456428
oneOf:

0 commit comments

Comments
 (0)