Only require base_dir and container for certain commands.

This commit is contained in:
Fabian Schlenz 2017-09-25 09:27:51 +02:00
parent 7a83662485
commit 648da782d4
1 changed files with 11 additions and 6 deletions

17
dup.rb
View File

@ -167,6 +167,8 @@ action = :run
container = nil
$dry_run = false
$pull = false
needs_container = true
needs_basedir = true
opts = GetoptLong.new(
[ '--sample', '-s', GetoptLong::NO_ARGUMENT ],
@ -182,6 +184,7 @@ opts.each do |opt, arg|
action_sample
when '--create'
action = :create
needs_basedir = true
when '--help'
action_help
when '--dry-run'
@ -194,15 +197,17 @@ end
container = ARGV.shift
if container==nil || container==""
if needs_container && (container==nil || container=="")
raise "No container given."
end
if ENV['DUP_DIR']
base_dir = ENV['DUP_DIR']
else
base_dir = File.join(Dir.home, ".dup")
puts "Environment variable DUP_DIR is not set. Looking for .yml files in #{base_dir}"
if needs_basedir
if ENV['DUP_DIR']
base_dir = ENV['DUP_DIR']
else
base_dir = File.join(Dir.home, ".dup")
puts "Environment variable DUP_DIR is not set. Looking for .yml files in #{base_dir}"
end
end
file = "%s/%s.yml" % [ base_dir, container ]