Skip to content

Commit ae1a32c

Browse files
committed
remove support for string value in filters
1 parent 7ee33b5 commit ae1a32c

File tree

12 files changed

+48
-62
lines changed

12 files changed

+48
-62
lines changed

examples/filters/README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ This example was generated with:
88
```bash
99
$ bashly init
1010
# ... now edit src/bashly.yml to match the example ...
11-
# ... now edit src/lib/filter_docker_running.sh to match the example ...
12-
# ... now edit src/lib/filter_redis_running.sh to match the example ...
11+
# ... now edit src/lib/filters.sh to match the example ...
1312
$ bashly generate
1413
```
1514

16-
<!-- include: src/lib/filter_docker_running.sh src/lib/filter_redis_running.sh -->
17-
18-
---
15+
<!-- include: src/lib/filters.sh -->
1916

2017
-----
2118

@@ -30,11 +27,11 @@ commands:
3027
- name: container
3128
help: Perform actions on a docker container
3229

33-
# The filters option can be a string or an array of strings.
3430
# When the command is executed, your script will look for a function named
3531
# "filter_docker_running" and execute it. If it prints a string, it will be
3632
# considered an error and the command execution will be halted.
37-
filters: docker_running
33+
filters:
34+
- docker_running
3835

3936
args:
4037
- name: id
@@ -43,26 +40,30 @@ commands:
4340

4441
- name: redis
4542
help: Perform actions in redis
46-
filters: [docker_running, redis_running]
43+
44+
# When multiple filters are present, the command will halt if any of them
45+
# prints an error string.
46+
filters:
47+
- docker_running
48+
- redis_running
4749
```
4850
49-
## `src/lib/filter_docker_running.sh`
51+
## `src/lib/filters.sh`
5052

5153
```bash
54+
# These filter functions can reside in any path under the `lib` directory.
55+
# You can use a single file for all filter functions, or a separate file
56+
# for each function.
57+
5258
# Print an error string if docker is not running.
5359
# The script will automatically exit if this function prints anything.
5460
filter_docker_running() {
5561
docker info > /dev/null 2>&1 || echo "Docker must be running"
5662
}
5763

58-
```
59-
60-
## `src/lib/filter_redis_running.sh`
61-
62-
```bash
6364
# This is just a sample filter designed to always fail
6465
filter_redis_running() {
65-
echo "Redis must be running (fake)"
66+
echo "Redis must be running (always fails)"
6667
}
6768

6869
```
@@ -85,7 +86,7 @@ args:
8586
### `$ ./cli redis`
8687

8788
```shell
88-
Redis must be running (fake)
89+
Redis must be running (always fails)
8990

9091

9192
```

examples/filters/src/bashly.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ commands:
66
- name: container
77
help: Perform actions on a docker container
88

9-
# The filters option can be a string or an array of strings.
109
# When the command is executed, your script will look for a function named
1110
# "filter_docker_running" and execute it. If it prints a string, it will be
1211
# considered an error and the command execution will be halted.
13-
filters: docker_running
12+
filters:
13+
- docker_running
1414

1515
args:
1616
- name: id
@@ -19,4 +19,9 @@ commands:
1919

2020
- name: redis
2121
help: Perform actions in redis
22-
filters: [docker_running, redis_running]
22+
23+
# When multiple filters are present, the command will halt if any of them
24+
# prints an error string.
25+
filters:
26+
- docker_running
27+
- redis_running

examples/filters/src/lib/filter_docker_running.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/filters/src/lib/filter_redis_running.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/filters/src/lib/filters.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# These filter functions can reside in any path under the `lib` directory.
2+
# You can use a single file for all filter functions, or a separate file
3+
# for each function.
4+
5+
# Print an error string if docker is not running.
6+
# The script will automatically exit if this function prints anything.
7+
filter_docker_running() {
8+
docker info > /dev/null 2>&1 || echo "Docker must be running"
9+
}
10+
11+
# This is just a sample filter designed to always fail
12+
filter_redis_running() {
13+
echo "Redis must be running (always fails)"
14+
}

lib/bashly/config_validator.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ def assert_extensible(key, value)
7272
"#{key} must be a boolean or a string"
7373
end
7474

75-
def assert_filters(key, value)
76-
return unless value
77-
assert [Array, String].include?(value.class),
78-
"#{key} must be an array or a string"
79-
80-
assert_array key, value, of: :string if value.is_a? Array
81-
end
82-
8375
def assert_arg(key, value)
8476
assert_hash key, value
8577
assert_string "#{key}.name", value['name']
@@ -137,13 +129,13 @@ def assert_command(key, value)
137129
assert_version "#{key}.version", value['version']
138130
assert_catch_all "#{key}.catch_all", value['catch_all']
139131
assert_extensible "#{key}.extensible", value['extensible']
140-
assert_filters "#{key}.filters", value['filters']
141132

142133
assert_array "#{key}.args", value['args'], of: :arg
143134
assert_array "#{key}.flags", value['flags'] , of: :flag
144135
assert_array "#{key}.commands", value['commands'], of: :command
145136
assert_array "#{key}.completions", value['completions'], of: :string
146137
assert_array "#{key}.dependencies", value['dependencies'], of: :string
138+
assert_array "#{key}.filters", value['filters'], of: :string
147139
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
148140
assert_array "#{key}.examples", value['examples'], of: :string
149141
end

lib/bashly/script/command.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ def filename
5858
options["filename"] || "#{action_name.to_underscore}_command.sh"
5959
end
6060

61-
# Returns an array of filters
62-
def filters
63-
return nil unless options["filters"]
64-
result = options["filters"]
65-
result.is_a?(Array) ? result : [result]
66-
end
67-
6861
# Returns an array of Flags
6962
def flags
7063
return [] unless options["flags"]

spec/approvals/examples/filters

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ run ./cli --help to test your bash script
1212
args:
1313
- ${args[id]} = sample-id
1414
+ ./cli redis
15-
Redis must be running (fake)
15+
Redis must be running (always fails)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.filters must be an array or a string>
1+
#<Bashly::ConfigurationError: root.filters[0] must be a string>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#<Bashly::ConfigurationError: root.filters must be an array or a string>
1+
#<Bashly::ConfigurationError: root.filters must be an array>

0 commit comments

Comments
 (0)