move vendor_deps to base_cli

Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
This commit is contained in:
Victoria Jeffrey 2016-12-01 08:33:35 -05:00 committed by Christoph Hartmann
parent b110c1fba5
commit 0991cd142f
4 changed files with 31 additions and 35 deletions

View file

@ -128,7 +128,7 @@ module Compliance
exit 1
end
Inspec::Profile.vendor(path, options) if File.directory?(path)
vendor_deps(path, options) if File.directory?(path)
o = options.dup
configure_logger(o)

View file

@ -146,6 +146,35 @@ module Inspec
end
end
def vendor_deps(path, opts)
path.nil? ? path = Pathname.new(Dir.pwd) : path = Pathname.new(path)
cache_path = path.join('vendor')
inspec_lock = path.join('inspec.lock')
if (cache_path.exist? || inspec_lock.exist?) && !opts[:overwrite]
puts 'Profile is already vendored. Use --overwrite.'
return false
end
# remove existing
FileUtils.rm_rf(cache_path) if cache_path.exist?
File.delete(inspec_lock) if inspec_lock.exist?
puts "Vendor dependencies of #{path} into #{cache_path}"
opts[:logger] = Logger.new(STDOUT)
opts[:logger].level = get_log_level(opts.log_level)
opts[:cache] = Inspec::Cache.new(cache_path.to_s)
opts[:backend] = Inspec::Backend.create(target: 'mock://')
configure_logger(opts)
# vendor dependencies and generate lockfile
profile = Inspec::Profile.for_target(path.to_s, opts)
lockfile = profile.generate_lockfile
File.write(inspec_lock, lockfile.to_yaml)
rescue StandardError => e
pretty_handle_exception(e)
end
def configure_logger(o)
#
# TODO(ssd): This is a big gross, but this configures the

View file

@ -111,14 +111,7 @@ class Inspec::InspecCLI < Inspec::BaseCLI # rubocop:disable Metrics/ClassLength
desc: 'Overwrite existing vendored dependencies and lockfile.'
def vendor(path = nil)
o = opts.dup
o[:logger] = Logger.new(STDOUT)
o[:logger].level = get_log_level(o.log_level)
configure_logger(o)
Inspec::Profile.vendor(path, o)
rescue StandardError => e
pretty_handle_exception(e)
vendor_deps(path, o)
end
desc 'archive PATH', 'archive a profile to tar.gz (default) or zip'

View file

@ -48,32 +48,6 @@ module Inspec
end
end
def self.vendor(path, opts)
puts 'Vendoring profile.'
path.nil? ? path = Pathname.new(Dir.pwd) : path = Pathname.new(path)
cache_path = path.join('vendor')
inspec_lock = path.join('inspec.lock')
if (cache_path.exist? || inspec_lock.exist?) && !opts[:overwrite]
puts 'Profile is already vendored. Use --overwrite.'
return false
end
# remove existing
FileUtils.rm_rf(cache_path) if cache_path.exist?
File.delete(inspec_lock) if inspec_lock.exist?
puts "Vendor dependencies of #{path} into #{cache_path}"
opts[:cache] = Inspec::Cache.new(cache_path.to_s)
opts[:backend] = Inspec::Backend.create(target: 'mock://')
# vendor dependencies and generate lockfile
profile = Inspec::Profile.for_target(path.to_s, opts)
lockfile = profile.generate_lockfile
File.write(inspec_lock, lockfile.to_yaml)
end
def self.for_path(path, opts)
file_provider = FileProvider.for_path(path)
rp = file_provider.relative_provider