File tree Expand file tree Collapse file tree 9 files changed +95
-29
lines changed
bashly/script/introspection Expand file tree Collapse file tree 9 files changed +95
-29
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,10 @@ Naming/AccessorMethodName:
26
26
- ' lib/bashly/concerns/indentation_helper.rb'
27
27
28
28
# FIXME: The `Command` class is too long
29
- Metrics/ClassLength : { Exclude: [lib/bashly/script/command.rb] }
29
+ Metrics/ClassLength :
30
+ Exclude :
31
+ - lib/bashly/script/command.rb
32
+ - lib/bashly/config_validator.rb
30
33
31
34
# Allow irregular filenames in some cases
32
35
RSpec/SpecFilePathFormat :
Original file line number Diff line number Diff line change @@ -22,13 +22,13 @@ module Bashly
22
22
module Script
23
23
autoloads 'bashly/script' , %i[
24
24
Argument Base CatchAll Command Dependency EnvironmentVariable Flag
25
- Wrapper
25
+ Variable Wrapper
26
26
]
27
27
28
28
module Introspection
29
29
autoloads 'bashly/script/introspection' , %i[
30
30
Arguments Commands Dependencies EnvironmentVariables Examples Flags
31
- Visibility
31
+ Variables Visibility
32
32
]
33
33
end
34
34
end
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ class Command < Base
8
8
include Introspection ::EnvironmentVariables
9
9
include Introspection ::Examples
10
10
include Introspection ::Flags
11
+ include Introspection ::Variables
11
12
include Introspection ::Visibility
12
13
13
14
class << self
Original file line number Diff line number Diff line change
1
+ module Bashly
2
+ module Script
3
+ module Introspection
4
+ module Variables
5
+ # Returns an array of Variable objects
6
+ def variables
7
+ return [ ] unless options [ 'variables' ]
8
+
9
+ options [ 'variables' ] . map do |options |
10
+ Variable . new options
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
Original file line number Diff line number Diff line change
1
+ module Bashly
2
+ module Script
3
+ class Variable < Base
4
+ class << self
5
+ def option_keys
6
+ @option_keys ||= %i[ name value ]
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
Original file line number Diff line number Diff line change 1
1
= view_marker
2
2
3
3
variables.each do |var|
4
- case var['value']
5
- when Array
6
- if var['value'].empty?
7
- > declare -a {{ var['name'] }}=()
8
- else
9
- > declare -a {{ var['name'] }}=(
10
- var['value'].each do |v|
11
- > "{{ v }}"
12
- end
13
- > )
14
- end
15
- when Hash
16
- if var['value'].empty?
17
- > declare -A {{ var['name'] }}=()
18
- else
19
- > declare -A {{ var['name'] }}=(
20
- var['value'].each do |k, v|
21
- > ["{{ k }}"]="{{ v }}"
22
- end
23
- > )
24
- end
25
- when String, NilClass
26
- > {{ var['name'] }}="{{ var['value'] }}"
27
- else
28
- > {{ var['name'] }}={{ var['value'] }}
29
- end
4
+ = var.render(:definition)
30
5
end
Original file line number Diff line number Diff line change
1
+ = view_marker
2
+
3
+ case value
4
+ when Array
5
+ if value.empty?
6
+ > declare -a {{ name }}=()
7
+ else
8
+ > declare -a {{ name }}=(
9
+ value.each do |v|
10
+ > "{{ v }}"
11
+ end
12
+ > )
13
+ end
14
+ when Hash
15
+ if value.empty?
16
+ > declare -A {{ name }}=()
17
+ else
18
+ > declare -A {{ name }}=(
19
+ value.each do |k, v|
20
+ > ["{{ k }}"]="{{ v }}"
21
+ end
22
+ > )
23
+ end
24
+ when String, NilClass
25
+ > {{ name }}="{{ value }}"
26
+ else
27
+ > {{ name }}={{ value }}
28
+ end
Original file line number Diff line number Diff line change
1
+ describe Script ::Introspection ::Variables do
2
+ subject do
3
+ result = Script ::Command . new fixtures [ fixture ]
4
+ result . parents = result . options [ 'parents' ]
5
+ result
6
+ end
7
+
8
+ let ( :fixtures ) { load_fixture 'script/commands' }
9
+ let ( :fixture ) { :variables }
10
+
11
+ describe '#variables' do
12
+ it 'returns an array of Variable objects' do
13
+ expect ( subject . variables ) . to be_an Array
14
+ expect ( subject . variables ) . to all ( be_a Script ::Variable )
15
+ end
16
+ end
17
+ end
Original file line number Diff line number Diff line change 489
489
repeatable : true
490
490
unique : true
491
491
492
+ :variables :
493
+ name : get
494
+ variables :
495
+ - name : debug
496
+ value : true
497
+ - name : url
498
+ value : http://hello.com
499
+ - name : number
500
+ value : 123
501
+ - name : array
502
+ value : [one, two]
503
+ - name : hash
504
+ value : { one: 1, two: 2 }
505
+ - name : empty
506
+
492
507
:whitelist :
493
508
name : cli
494
509
args :
You can’t perform that action at this time.
0 commit comments