Skip to content

Commit 03e08db

Browse files
committed
- Add bashly validate CLI command
1 parent 828358f commit 03e08db

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

lib/bashly/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def self.runner
1010

1111
runner.route 'init', to: Commands::Init
1212
runner.route 'preview', to: Commands::Preview
13+
runner.route 'validate', to: Commands::Validate
1314
runner.route 'generate', to: Commands::Generate
1415
runner.route 'add', to: Commands::Add
1516

lib/bashly/commands/validate.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Bashly
2+
module Commands
3+
class Validate < Base
4+
help "Scan the configuration file for errors"
5+
6+
usage "bashly validate"
7+
usage "bashly validate (-h|--help)"
8+
9+
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
10+
11+
def run
12+
config = Config.new "#{Settings.source_dir}/bashly.yml"
13+
validator = ConfigValidator.new config
14+
validator.validate
15+
say "!txtgrn!OK"
16+
end
17+
end
18+
end
19+
end

spec/approvals/cli/commands

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ Bashly - Bash CLI Generator
33
Commands:
44
init Initialize a new workspace
55
preview Generate the bash script to STDOUT
6+
validate Scan the configuration file for errors
67
generate Generate the bash script and required files
78
add Add extra features and customization to your script

spec/approvals/cli/validate/help

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Scan the configuration file for errors
2+
3+
Usage:
4+
bashly validate
5+
bashly validate (-h|--help)
6+
7+
Options:
8+
-h --help
9+
Show this help
10+
11+
Environment Variables:
12+
BASHLY_SOURCE_DIR
13+
The path containing the bashly configuration and source files [default: src]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require 'spec_helper'
2+
3+
describe Commands::Validate do
4+
let(:source_dir) { Settings.source_dir }
5+
subject { CLI.runner }
6+
7+
context "with --help" do
8+
it "shows long usage" do
9+
expect{ subject.run %w[validate --help] }.to output_approval('cli/validate/help')
10+
end
11+
end
12+
13+
context "without arguments" do
14+
before do
15+
reset_tmp_dir
16+
success = system "mkdir -p #{source_dir} && cp lib/bashly/templates/bashly.yml #{source_dir}/bashly.yml"
17+
expect(success).to be true
18+
end
19+
20+
it "validates the script" do
21+
expect { subject.run %w[validate] }.to output("OK\n").to_stdout
22+
end
23+
end
24+
25+
end

0 commit comments

Comments
 (0)