Class: Zold::Clean
- Inherits:
-
Object
- Object
- Zold::Clean
- Defined in:
- lib/zold/commands/clean.rb
Overview
CLEAN command
Instance Method Summary collapse
- #clean(cps, _) ⇒ Object
-
#initialize(wallets:, copies:, log: Log::NULL) ⇒ Clean
constructor
A new instance of Clean.
- #run(args = []) ⇒ Object
Constructor Details
Instance Method Details
#clean(cps, _) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/zold/commands/clean.rb', line 68 def clean(cps, _) start = Time.now deleted = cps.clean list = cps.all.map do |c| wallet = Wallet.new(c[:path]) "#{c[:name]}: #{c[:score]} #{wallet.mnemo} \ #{Size.new(File.size(c[:path]))}/#{Age.new(File.mtime(c[:path]))}" end @log.debug( "#{deleted} expired local copies removed for #{cps} \ in #{Age.new(start, limit: 0.01)}, \ #{list.empty? ? 'nothing left' : "#{list.count} left:\n#{list.join("\n")}"}" ) end |
#run(args = []) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/zold/commands/clean.rb', line 52 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = "Usage: zold clean [ID...] [options] Available options:" o.integer '--threads', 'How many threads to use for cleaning copies (default: 1)', default: 1 o.bool '--help', 'Print instructions' end mine = Args.new(opts, @log).take || return list = mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) } Hands.exec(opts['threads'], list.uniq) do |id| clean(Copies.new(File.join(@copies, id), log: @log), opts) end end |