Skip to content

Commit 45781fc

Browse files
authored
Merge pull request #280 from DannyBen/add/validate-verbose
Add `--verbose` to `bashly validate`, to show the compiled config
2 parents 25d845c + fe04c9e commit 45781fc

File tree

9 files changed

+76
-3
lines changed

9 files changed

+76
-3
lines changed

bashly.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Gem::Specification.new do |s|
2222
s.add_runtime_dependency 'gtx', '~> 0.1.0'
2323

2424
s.add_runtime_dependency 'colsole', '~> 0.7'
25+
s.add_runtime_dependency 'filewatcher', '~> 2.0'
26+
s.add_runtime_dependency 'lp', '~> 0.2'
2527
s.add_runtime_dependency 'mister_bin', '~> 0.7'
2628
s.add_runtime_dependency 'requires', '~> 0.2'
27-
s.add_runtime_dependency 'filewatcher', '~> 2.0'
2829

2930
s.metadata = {
3031
"bug_tracker_uri" => "https://github.com/DannyBen/bashly/issues",

lib/bashly/commands/validate.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ module Commands
33
class Validate < Base
44
help "Scan the configuration file for errors"
55

6-
usage "bashly validate"
6+
usage "bashly validate [--verbose]"
77
usage "bashly validate (-h|--help)"
88

9+
option "-v --verbose", "Show the bashly configuration file prior to validating. This is useful when using split config (import) since it will show the final compiled configuration."
10+
911
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
1012

1113
def run
14+
if args['--verbose']
15+
lp config
16+
puts "---"
17+
end
1218
validate_config
1319
show_deprecations
1420
deprecations = config_validator.deprecations

spec/approvals/cli/validate/help

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
Scan the configuration file for errors
22

33
Usage:
4-
bashly validate
4+
bashly validate [--verbose]
55
bashly validate (-h|--help)
66

77
Options:
8+
-v --verbose
9+
Show the bashly configuration file prior to validating. This is useful when
10+
using split config (import) since it will show the final compiled
11+
configuration.
12+
813
-h --help
914
Show this help
1015

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
name: cli
3+
commands:
4+
- name: invalid
5+
help: This one will not validate
6+
commands:
7+
name: nested
8+
help: Not an array
9+
---
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: cli
3+
commands:
4+
- name: toplevel
5+
help: The toplevel command namespace
6+
commands:
7+
- name: nested
8+
help: The nested command
9+
---
10+
OK

spec/bashly/commands/validate_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@
2121
end
2222
end
2323

24+
context "with --verbose" do
25+
before do
26+
reset_tmp_dir create_src: true
27+
cp 'spec/fixtures/workspaces/import/*'
28+
end
29+
30+
it "shows the compiled config file prior to validation" do
31+
expect { subject.run %w[validate -v] }.to output_approval('cli/validate/verbose-valid')
32+
end
33+
34+
context "when the compiled config is invalid" do
35+
before do
36+
reset_tmp_dir create_src: true
37+
cp 'spec/fixtures/invalid.yml', "#{source_dir}/bashly.yml"
38+
end
39+
40+
it "still shows it prior to validation" do
41+
expect { subject.run %w[validate -v] }.to raise_error(ConfigurationError)
42+
.and output_approval('cli/validate/verbose-invalid')
43+
end
44+
end
45+
end
46+
2447
# DEPRECATION 0.8.0
2548
context "with deprecated command.short option" do
2649
before do

spec/fixtures/invalid.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: cli
2+
3+
commands:
4+
- name: invalid
5+
help: This one will not validate
6+
commands:
7+
name: nested
8+
help: Not an array
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: cli
2+
3+
commands:
4+
- name: toplevel
5+
help: "The toplevel command namespace"
6+
commands:
7+
- import: spec/tmp/src/nested_command.sh
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: nested
2+
help: "The nested command"
3+
---
4+
inspect_args

0 commit comments

Comments
 (0)