Class: Zold::Remove
- Inherits:
-
Object
- Object
- Zold::Remove
- Includes:
- ThreadBadge
- Defined in:
- lib/zold/commands/remove.rb
Overview
REMOVE command
Instance Method Summary collapse
-
#initialize(wallets:, log: Log::NULL) ⇒ Remove
constructor
A new instance of Remove.
- #remove(id, opts) ⇒ Object
- #run(args = []) ⇒ Object
Constructor Details
Instance Method Details
#remove(id, opts) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/zold/commands/remove.rb', line 59 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 = []) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/zold/commands/remove.rb', line 43 def run(args = []) @log.debug("Remove.run(#{args.join(' ')})") opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = "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 |