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

17
dup.rb
View File

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