Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better config file locating #390

Merged
merged 2 commits into from
Feb 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/wraith/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def copy_old_shots(config_name)
desc "validate", "checks your configuration and validates that all required properties exist"
def validate(config_name)
within_acceptable_limits do
Wraith::Validate.new(config_name).validate
logger.info Wraith::Validate.new(config_name).validate
end
end

Expand Down
22 changes: 15 additions & 7 deletions lib/wraith/wraith.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ class Wraith::Wraith
def initialize(config, yaml_passed = false)
@config = yaml_passed ? config : open_config_file(config)
logger.level = verbose ? Logger::DEBUG : Logger::INFO
rescue
logger.error "unable to find config at #{config}"
end

def open_config_file(config_name)
if File.exist?(config_name) && File.extname(config_name) == ".yaml"
config = File.open config_name
else
config = File.open "configs/#{config_name}.yaml"
possible_filenames = [
config_name,
"#{config_name}.yml",
"#{config_name}.yaml",
"configs/#{config_name}.yml",
"configs/#{config_name}.yaml"
]

possible_filenames.each do |filepath|
if File.exist?(filepath)
config = File.open config_name
return YAML.load config
end
end
YAML.load config
rescue
logger.error "unable to find config \"#{config}\""
end

def directory
Expand Down