lib/artifactory/cleaner/cli.rb in artifactory-cleaner-1.0.3 vs lib/artifactory/cleaner/cli.rb in artifactory-cleaner-1.0.4
- old
+ new
@@ -53,13 +53,13 @@
# Constructor for a new CLI interface
def initialize(*args)
super
@config = {}
begin
- load_conf_file options.conf_file if options.conf_file
+ load_conf_file options[:conf_file] if options[:conf_file]
rescue => ex
- STDERR.puts "Unable to load config from #{options.conf_file}: #{ex}"
+ STDERR.puts "Unable to load config from #{options[:conf_file]}: #{ex}"
exit Sysexits::EX_DATAERR
end
@artifactory_config = {
endpoint: options[:endpoint] || @config['endpoint'],
api_key: options[:api_key] || @config['api-key'],
@@ -109,25 +109,25 @@
option :threads, :type => :numeric, :default => 4
##
# Analyze usage and report where space is used
def usage_report
begin
- from = Time.parse(options.from)
- to = Time.parse(options.to)
+ from = Time.parse(options[:from])
+ to = Time.parse(options[:to])
rescue => ex
STDERR.puts "Unable to parse time format. Please use: YYYY-MM-DD HH:II:SS"
STDERR.puts ex
exit Sysexits::EX_USAGE
end
begin
- STDERR.puts "[DEBUG] controller.bucketize_artifacts from #{from} to #{to} repos #{options.repos}" if options.verbose?
+ STDERR.puts "[DEBUG] controller.bucketize_artifacts from #{from} to #{to} repos #{options[:repos]}" if options.verbose?
buckets = @controller.bucketize_artifacts(
from: from,
to: to,
- repos: options.repos,
- threads: options.threads,
+ repos: options[:repos],
+ threads: options[:threads],
)
@controller.bucketized_artifact_report(buckets).each { |l| STDERR.puts l }
if options.details?
puts "# Detailed Bucket Report:"
@@ -190,11 +190,11 @@
artifact_count: 0,
bytes: 0
}
}
- @controller.with_discovered_artifacts(from: dates[:from], to: dates[:to], repos: options.repos, threads: options.threads) do |artifact|
+ @controller.with_discovered_artifacts(from: dates[:from], to: dates[:to], repos: options[:repos], threads: options[:threads]) do |artifact|
if artifact_meets_criteria(artifact, dates, filter)
if options.dry_run?
STDERR.puts "Would archive #{artifact} to #{archive_to}"
else
@controller.archive_artifact artifact, archive_to
@@ -250,12 +250,12 @@
artifact_count: 0,
bytes: 0
}
}
- STDERR.puts "[DEBUG] controller.bucketize_artifacts from #{dates[:from]} to #{dates[:to]} repos #{options.repos}" if options.verbose?
- @controller.with_discovered_artifacts(from: dates[:from], to: dates[:to], repos: options.repos, threads: options.threads) do |artifact|
+ STDERR.puts "[DEBUG] controller.bucketize_artifacts from #{dates[:from]} to #{dates[:to]} repos #{options[:repos]}" if options.verbose?
+ @controller.with_discovered_artifacts(from: dates[:from], to: dates[:to], repos: options[:repos], threads: options[:threads]) do |artifact|
if artifact_meets_criteria(artifact, dates, filter)
if archive_to
if options.dry_run?
STDERR.puts "Would archive #{artifact} to #{archive_to}"
else
@@ -305,14 +305,14 @@
##
# return Ruby Time objects formed from CLI switches `--to`, `--from`, `--ctreated-before` etc
def parse_date_options
dates = {}
- dates[:from] = Time.parse(options.from) if options.from
- dates[:created_before] = Time.parse(options.created_before) if options.created_before
- dates[:modified_before] = Time.parse(options.modified_before) if options.modified_before
- dates[:last_used_before] = Time.parse(options.last_used_before) if options.last_used_before
+ dates[:from] = Time.parse(options[:from]) if options[:from]
+ dates[:created_before] = Time.parse(options[:created_before]) if options[:created_before]
+ dates[:modified_before] = Time.parse(options[:modified_before]) if options[:modified_before]
+ dates[:last_used_before] = Time.parse(options[:last_used_before]) if options[:last_used_before]
dates[:to] = [dates[:created_before], dates[:modified_before], dates[:downloaded_before], dates[:last_used_before]].compact.sort.first
if dates[:to].nil?
STDERR.puts "At least one end date for search must be provided (--created-before, --modified-before, --downloaded-before or --last-used-before)"
exit Sysexits::EX_USAGE
@@ -322,11 +322,11 @@
end
##
# Parse and validate value for the `--archive-to` CLI switch, ensuring it points to a valid, writable directory
def parse_archive_option
- archive_to = options.archive_to
+ archive_to = options[:archive_to]
if archive_to
unless File.directory? archive_to
STDERR.puts "#{archive_to} is not a directory. `--archive-to` expects a valid, existing directory under which to store archived artifacts"
exit Sysexits::EX_USAGE
end
@@ -341,16 +341,16 @@
##
# Load Artifactory::Cleaner::ArtifactFilter objects from a YAML file
def load_artifact_filter
filter = ArtifactFilter.new
- if options.filter
- unless File.exist? options.filter and File.readable? options.filter
- STDERR.puts "Unable to read specified filter file #{options.filter}"
+ if options[:filter]
+ unless File.exist? options[:filter] and File.readable? options[:filter]
+ STDERR.puts "Unable to read specified filter file #{options[:filter]}"
exit Sysexits::EX_USAGE
end
- rules = YAML.load_file options.filter
+ rules = YAML.load_file options[:filter]
rules.each {|rule| filter << rule}
end
filter
end
@@ -374,14 +374,14 @@
##
# Helper method for generating CLI terminal-friendly tables of output
def get_repo_cols(repo_kinds)
if options.details?
selected_cols =
- if options.output.nil?
+ if options[:output].nil?
Artifactory::Cleaner::CLI.default_repo_table_cols
else
- options.output.split(',').map &:to_sym
+ options[:output].split(',').map &:to_sym
end
@repo_table_cols.select do |col|
(col.only.nil? or repo_kinds.include? col.only) and (selected_cols.include? col.method)
end
else
@@ -390,10 +390,10 @@
end
##
# CLI helper method for printing details of discovered repositories to a terminal
def print_repo_list(repo_info_table, include_cols)
- if options.no_headers || !options.details
+ if options[:no_headers] || !options[:details]
repo_info_table.each {|row| puts row.join("\t")}
else
headers = include_cols.map &:heading
widths = headers.map {|h| h.length + 1}
repo_info_table.each do |row|