File tree Expand file tree Collapse file tree 10 files changed +36
-0
lines changed
spec/fixtures/workspaces/flag-args-with-dash Expand file tree Collapse file tree 10 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,15 @@ class Argument < Base
44 def usage_string
55 required ? name . upcase : "[#{ name . upcase } ]"
66 end
7+
8+ def validations
9+ return [ ] unless options [ 'validate' ]
10+ if options [ 'validate' ] . is_a? String
11+ [ options [ 'validate' ] ]
12+ else
13+ options [ 'validate' ]
14+ end
15+ end
716 end
817 end
918end
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ class Base
2525 parent_name
2626 required
2727 short
28+ validate
2829 version
2930 ]
3031
Original file line number Diff line number Diff line change @@ -21,6 +21,15 @@ def usage_string(extended: false)
2121 result << strings [ :required ] if required and extended
2222 result . join " "
2323 end
24+
25+ def validations
26+ return [ ] unless options [ 'validate' ]
27+ if options [ 'validate' ] . is_a? String
28+ [ options [ 'validate' ] ]
29+ else
30+ options [ 'validate' ]
31+ end
32+ end
2433 end
2534 end
2635end
Original file line number Diff line number Diff line change @@ -32,3 +32,4 @@ missing_dependency: "missing dependency: %{dependency}"
3232disallowed_flag : " %{name} must be one of: %{allowed}"
3333disallowed_argument : " %{name} must be one of: %{allowed}"
3434unsupported_bash_version : " bash version 4 or higher is required"
35+ validation_error : " validation error: %s"
Original file line number Diff line number Diff line change 1+ % validations.each do |validation_function|
2+ if [[ -n $(validate_<%= validation_function %> "$1") ]]; then
3+ printf "<%= strings[:validation_error] %> \n" "<%= name.upcase %> $(validate_<%= validation_function %> "$1")"
4+ exit 1
5+ fi
6+ % end
Original file line number Diff line number Diff line change 33% condition = "if"
44% args.each do |arg|
55<%= condition %> [[ ! ${args[<%= arg.name %> ]} ]]; then
6+ <%= arg.render(:validations).indent 2 %>
67 args[<%= arg.name %> ]=$1
78 shift
89% condition = "elif"
Original file line number Diff line number Diff line change 11# :command.required_args_filter
22% required_args.each do |arg|
33if [[ $1 && $1 != -* ]]; then
4+ <%= arg.render(:validations).indent 2 %>
45 args[<%= arg.name %> ]=$1
56 shift
67else
Original file line number Diff line number Diff line change 22<%= aliases.join " | " %> )
33% if arg
44 if [[ $2 ]]; then
5+ <%= render(:validations).indent 4 %>
56 args[<%= name %> ]="$2"
67 shift
78 shift
Original file line number Diff line number Diff line change 1+ % validations.each do |validation_function|
2+ if [[ -n $(validate_<%= validation_function %> "$2") ]]; then
3+ printf "<%= strings[:validation_error] %> \n" "<%= usage_string %> $(validate_<%= validation_function %> "$2")"
4+ exit 1
5+ fi
6+ % end
Original file line number Diff line number Diff line change @@ -143,6 +143,7 @@ parse_requirements() {
143143 # :flag.case
144144 --options | -o )
145145 if [[ $2 ]]; then
146+
146147 args[--options]=" $2 "
147148 shift
148149 shift
You can’t perform that action at this time.
0 commit comments