bin/hammer in hammer_cli-0.3.0 vs bin/hammer in hammer_cli-0.4.0
- old
+ new
@@ -12,11 +12,13 @@
# Create fake command instance to use some global args before we start.
# Option descriptions are never displayed and thus do not require translation.
class PreParser < Clamp::Command
option ["-v", "--verbose"], :flag, "be verbose"
option ["-d", "--debug"], :flag, "show debugging output"
- option ["-c", "--config"], "CFG_FILE", "path to custom config file"
+ option ["-c", "--config"], "CFG_FILE", "path to custom config file" do |path|
+ File.expand_path path
+ end
option ["-u", "--username"], "USERNAME", "username to access the remote system"
option ["-p", "--password"], "PASSWORD", "password to access the remote system"
option ["-s", "--server"], "SERVER", "remote system address"
option ["-r", "--reload-cache"], :flag, "force reload of Apipie cache"
option ["--interactive"], "INTERACTIVE", "Explicitly turn interactive mode on/off" do |value|
@@ -50,14 +52,22 @@
HammerCLI::Settings.path_history.each { |p| warn " #{p} -> #{p.gsub('hammer.modules.d', 'cli.modules.d').gsub('foreman/', 'hammer/')}"}
end
CFG_PATH_LOCAL = ['./config/']
+HammerCLI::Settings.load_from_paths CFG_PATH_LOCAL
+
if preparser.config
- CFG_PATH_LOCAL.unshift preparser.config
+ if File.file? preparser.config
+ HammerCLI::Settings.load_from_file preparser.config
+ elsif File.directory? preparser.config
+ HammerCLI::Settings.load_from_paths [preparser.config]
+ else
+ $stderr.puts _('Error: Custom configuration file %s does not exist.') % preparser.config
+ require 'hammer_cli/exit_codes'
+ exit HammerCLI::EX_CONFIG
+ end
end
-
-HammerCLI::Settings.load_from_paths CFG_PATH_LOCAL
# store username and password in settings
HammerCLI::Settings.load({
:_params => {
:username => preparser.username,