class Zold::Remove
REMOVE command
Public Class Methods
new(wallets:, log: Log::NULL)
click to toggle source
# File lib/zold/commands/remove.rb, line 38 def initialize(wallets:, log: Log::NULL) @wallets = wallets @log = log end
Public Instance Methods
remove(id, opts)
click to toggle source
# File lib/zold/commands/remove.rb, line 58 def remove(id, opts) @wallets.acq(id, exclusive: true) do |w| if w.exists? File.delete(w.path) else raise "Wallet #{id} doesn't exist in #{w.path}" unless opts['force'] @log.info("Wallet #{id} file not found in #{w.path}") end end @log.info("Wallet #{id} removed") end
run(args = [])
click to toggle source
# File lib/zold/commands/remove.rb, line 43 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o.banner = "Usage: zold remove [ID...] [options] Available options:" o.bool '--force', 'Don\'t report any errors if the wallet doesn\'t exist', default: false o.bool '--help', 'Print instructions' end mine = Args.new(opts, @log).take || return (mine.empty? ? @wallets.all : mine.map { |i| Id.new(i) }).each do |id| remove(id, opts) end end