Skip to content

Commit 5bd1bc2

Browse files
committed
refactor config handling in commands
1 parent 8a301d3 commit 5bd1bc2

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

lib/bashly/commands/base.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ module Commands
66
class Base < MisterBin::Command
77
include AssetHelper
88

9+
def config
10+
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
11+
end
12+
13+
def config_validator
14+
@config_validator ||= ConfigValidator.new config
15+
end
16+
917
def validate_config
10-
config = Config.new "#{Settings.source_dir}/bashly.yml"
11-
validator = ConfigValidator.new config
12-
validator.validate
18+
config_validator.validate
1319
end
1420
end
1521
end

lib/bashly/commands/generate.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ def master_script_path
128128
"#{Settings.target_dir}/#{command.name}"
129129
end
130130

131-
def config
132-
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
133-
end
134-
135131
def command
136132
@command ||= Script::Command.new config
137133
end

lib/bashly/commands/preview.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class Preview < Base
99
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
1010

1111
def run
12-
config = Config.new "#{Settings.source_dir}/bashly.yml"
13-
command = Script::Command.new(config)
12+
validate_config
13+
command = Script::Command.new config
1414
script = Script::Wrapper.new command
1515
puts script.code
1616
end

0 commit comments

Comments
 (0)