Skip to content

Commit 4cd8940

Browse files
authored
Merge pull request #662 from bashly-framework/fix/double-env-var-validation
Fix validation running twice for environment variables
2 parents 898a4f3 + 4d7e6d6 commit 4cd8940

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

lib/bashly/script/argument.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def default_string
2121
end
2222
end
2323

24-
def usage_string
25-
required ? label : "[#{label}]"
26-
end
27-
2824
def label
2925
repeatable ? "#{name.upcase}..." : name.upcase
3026
end
27+
28+
def usage_string
29+
required ? label : "[#{label}]"
30+
end
3131
end
3232
end
3333
end

lib/bashly/script/environment_variable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class EnvironmentVariable < Base
66
class << self
77
def option_keys
88
@option_keys ||= %i[
9-
allowed default help name required private validate
9+
allowed default help name private required validate
1010
]
1111
end
1212
end

lib/bashly/script/flag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class << self
1010
def option_keys
1111
@option_keys ||= %i[
1212
allowed arg completions conflicts default help long needs
13-
repeatable required short unique validate private
13+
private repeatable required short unique validate
1414
]
1515
end
1616
end

lib/bashly/views/argument/validations.gtx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ if validate
1414
> done
1515
> fi
1616
else
17-
> validation_output="$(validate_{{ validate }} "${args['{{ name }}']:-}")"
18-
> if [[ -v args['{{ name }}'] && -n "$validation_output" ]]; then
19-
> printf "{{ strings[:validation_error] }}\n" "{{ name.upcase }}" "$validation_output" >&2
20-
> exit 1
17+
> if [[ -v args['{{ name }}'] ]]; then
18+
> validation_output="$(validate_{{ validate }} "${args['{{ name }}']:-}")"
19+
> if [[ -n "$validation_output" ]]; then
20+
> printf "{{ strings[:validation_error] }}\n" "{{ name.upcase }}" "$validation_output" >&2
21+
> exit 1
22+
> fi
2123
> fi
2224
>
2325
end
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
if validate
22
= view_marker
33

4-
> if [[ -v {{ name.upcase }} && -n $(validate_{{ validate }} "${{ name.upcase }}") ]]; then
5-
> printf "{{ strings[:environment_variable_validation_error] }}\n" "{{ usage_string }}" "$(validate_{{ validate }} "${{ name.upcase }}")" >&2
6-
> exit 1
4+
> if [[ -v {{ name.upcase }} ]]; then
5+
> validation_output="$(validate_{{ validate }} "${{ name.upcase }}")"
6+
> if [[ -n "${validation_output}" ]]; then
7+
> printf "{{ strings[:environment_variable_validation_error] }}\n" "{{ usage_string }}" "$validation_output" >&2
8+
> exit 1
9+
> fi
710
> fi
811
>
912
end

0 commit comments

Comments
 (0)