Class: Zold::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/commands/create.rb

Overview

Create command

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, pubkey:, log: Log::Quiet.new) ⇒ Create

Returns a new instance of Create.



32
33
34
35
36
# File 'lib/zold/commands/create.rb', line 32

def initialize(wallets:, pubkey:, log: Log::Quiet.new)
  @wallets = wallets
  @pubkey = pubkey
  @log = log
end

Instance Method Details

#create(id, _) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/zold/commands/create.rb', line 51

def create(id, _)
  wallet = @wallets.find(id)
  wallet.init(id, @pubkey)
  @log.info(wallet.id)
  @log.debug("Wallet #{Rainbow(wallet).green} \
created at #{@wallets.path}")
  wallet
end

#run(args = []) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zold/commands/create.rb', line 38

def run(args = [])
  opts = Slop.parse(args, help: true) do |o|
    o.banner = "Usage: zold create [options]
Available options:"
    o.bool '--help', 'Print instructions'
  end
  if opts.help?
    @log.info(opts.to_s)
    return
  end
  create(opts.arguments.empty? ? Id.new : Id.new(opts.arguments[0]), opts)
end