Skip to content

Add specs for default_string (arg and flag) #475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2023
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: bundle exec rspec

static_analysis:
name: Static analysis of Example files
name: Example files static analysis

runs-on: ubuntu-latest

Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
run: bundle exec run shfmt

json_schema:
name: Validate JSON schemas
name: JSON schemas validation

runs-on: ubuntu-latest

Expand Down
130 changes: 39 additions & 91 deletions schemas/bashly.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,44 @@
},
"additionalProperties": false
},
"environment-variable": {
"title": "environment variable",
"description": "An environment variable of the current application\nhttps://bashly.dannyb.co/configuration/environment-variable/#environment-variable",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"$ref": "#/definitions/environment-variables-name-property"
},
"help": {
"$ref": "#/definitions/environment-variables-help-property"
},
"private": {
"$ref": "#/definitions/environment-variables-private-property"
},
"required": {
"$ref": "#/definitions/environment-variables-required-property"
},
"allowed": {
"$ref": "#/definitions/environment-variables-allowed-property"
},
"default": {
"$ref": "#/definitions/environment-variables-default-property"
}
},
"patternProperties": {
"^x_.": {
"title": "custom property",
"description": "A custom property of any type",
"examples": [
"Anything"
]
}
},
"additionalProperties": false
},
"name-property": {
"title": "name",
"description": "A name of the current script or sub-command\nhttps://bashly.dannyb.co/configuration/command/#name",
Expand Down Expand Up @@ -442,97 +480,7 @@
"type": "array",
"uniqueItems": true,
"items": {
"title": "environment variable",
"description": "An environment variable of the current application\nhttps://bashly.dannyb.co/configuration/environment-variable/#environment-variable",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"$ref": "#/definitions/environment-variables-name-property"
},
"help": {
"$ref": "#/definitions/environment-variables-help-property"
},
"default": {
"$ref": "#/definitions/environment-variables-default-property"
},
"private": {
"$ref": "#/definitions/environment-variables-private-property"
},
"required": {
"$ref": "#/definitions/environment-variables-required-property"
},
"allowed": {
"$ref": "#/definitions/environment-variables-allowed-property"
}
},
"if": {
"properties": {
"required": {
"const": false
}
}
},
"then": {
"properties": {
"name": {
"$ref": "#/definitions/environment-variables-name-property"
},
"help": {
"$ref": "#/definitions/environment-variables-help-property"
},
"default": {
"$ref": "#/definitions/environment-variables-default-property"
},
"private": {
"$ref": "#/definitions/environment-variables-private-property"
},
"required": {
"$ref": "#/definitions/environment-variables-required-property"
},
"allowed": {
"$ref": "#/definitions/environment-variables-allowed-property"
}
},
"patternProperties": {
"^x_.": {
"title": "custom property",
"description": "A custom property of any type",
"examples": [
"Anything"
]
}
},
"additionalProperties": false
},
"else": {
"properties": {
"name": {
"$ref": "#/definitions/environment-variables-name-property"
},
"help": {
"$ref": "#/definitions/environment-variables-help-property"
},
"private": {
"$ref": "#/definitions/environment-variables-private-property"
},
"required": {
"$ref": "#/definitions/environment-variables-required-property"
}
},
"patternProperties": {
"^x_.": {
"title": "custom property",
"description": "A custom property of any type",
"examples": [
"Anything"
]
}
},
"additionalProperties": false
}
"$ref": "#/definitions/environment-variable"
}
},
"examples-property": {
Expand Down
26 changes: 26 additions & 0 deletions spec/bashly/script/argument_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@

let(:fixture) { :basic_argument }

describe '#default_string' do
context 'when default is an array' do
let(:fixture) { :default_array }

it 'returns a shell-escaped string suitable to be shell array source' do
expect(subject.default_string).to eq 'spaced\\ one two'
end
end

context 'when default is string and repeatable is false' do
let(:fixture) { :default_string }

it 'returns it as is' do
expect(subject.default_string).to eq 'spaced one'
end
end

context 'when default is string and repeatable is true' do
let(:fixture) { :default_string_with_repeatable }

it 'returns a single string' do
expect(subject.default_string).to eq 'spaced\\ one'
end
end
end

describe '#usage_string' do
it 'returns a string suitable to be used as a usage pattern' do
expect(subject.usage_string).to eq '[FILE]'
Expand Down
26 changes: 26 additions & 0 deletions spec/bashly/script/flag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@
end
end

describe '#default_string' do
context 'when default is an array' do
let(:fixture) { :default_array }

it 'returns a shell-escaped string suitable to be shell array source' do
expect(subject.default_string).to eq 'spaced\\ one two'
end
end

context 'when default is string and repeatable is false' do
let(:fixture) { :default_string }

it 'returns it as is' do
expect(subject.default_string).to eq 'spaced one'
end
end

context 'when default is string and repeatable is true' do
let(:fixture) { :default_string_with_repeatable }

it 'returns a single string' do
expect(subject.default_string).to eq 'spaced\\ one'
end
end
end

describe '#name' do
context 'with both short and long options' do
it 'returns the long option' do
Expand Down
15 changes: 15 additions & 0 deletions spec/fixtures/script/arguments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,18 @@
:repeatable:
name: file
repeatable: true

:default_string:
name: file
repeatable: false
default: spaced one

:default_array:
name: file
repeatable: true
default: [spaced one, two]

:default_string_with_repeatable:
name: file
repeatable: true
default: spaced one
20 changes: 19 additions & 1 deletion spec/fixtures/script/flags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@
:completions_completions:
long: --path
short: -p
completions: [<file>, README.md]
completions: [<file>, README.md]

:default_string:
long: --file
arg: path
repeatable: false
default: spaced one

:default_array:
long: --file
arg: path
repeatable: true
default: [spaced one, two]

:default_string_with_repeatable:
long: --file
arg: path
repeatable: true
default: spaced one
76 changes: 24 additions & 52 deletions support/schema/bashly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,29 @@ definitions:
const: true
patternProperties: *custom-properties
additionalProperties: false
environment-variable:
title: environment variable
description: |-
An environment variable of the current application
https://bashly.dannyb.co/configuration/environment-variable/#environment-variable
type: object
required:
- name
properties:
name:
$ref: '#/definitions/environment-variables-name-property'
help:
$ref: '#/definitions/environment-variables-help-property'
private:
$ref: '#/definitions/environment-variables-private-property'
required:
$ref: '#/definitions/environment-variables-required-property'
allowed:
$ref: '#/definitions/environment-variables-allowed-property'
default:
$ref: '#/definitions/environment-variables-default-property'
patternProperties: *custom-properties
additionalProperties: false
name-property:
title: name
description: |-
Expand Down Expand Up @@ -399,58 +422,7 @@ definitions:
type: array
uniqueItems: true
items:
title: environment variable
description: |-
An environment variable of the current application
https://bashly.dannyb.co/configuration/environment-variable/#environment-variable
type: object
required:
- name
properties:
name:
$ref: '#/definitions/environment-variables-name-property'
help:
$ref: '#/definitions/environment-variables-help-property'
default:
$ref: '#/definitions/environment-variables-default-property'
private:
$ref: '#/definitions/environment-variables-private-property'
required:
$ref: '#/definitions/environment-variables-required-property'
allowed:
$ref: '#/definitions/environment-variables-allowed-property'
if:
properties:
required:
const: false
then:
properties:
name:
$ref: '#/definitions/environment-variables-name-property'
help:
$ref: '#/definitions/environment-variables-help-property'
default:
$ref: '#/definitions/environment-variables-default-property'
private:
$ref: '#/definitions/environment-variables-private-property'
required:
$ref: '#/definitions/environment-variables-required-property'
allowed:
$ref: '#/definitions/environment-variables-allowed-property'
patternProperties: *custom-properties
additionalProperties: false
else:
properties:
name:
$ref: '#/definitions/environment-variables-name-property'
help:
$ref: '#/definitions/environment-variables-help-property'
private:
$ref: '#/definitions/environment-variables-private-property'
required:
$ref: '#/definitions/environment-variables-required-property'
patternProperties: *custom-properties
additionalProperties: false
$ref: '#/definitions/environment-variable'
examples-property:
title: examples
oneOf:
Expand Down