Class: Zold::Remote

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

Overview

Remote command

Instance Method Summary collapse

Constructor Details

#initialize(remotes:, farm: Farm::Empty.new, log: Log::Quiet.new) ⇒ Remote

Returns a new instance of Remote.


43
44
45
46
47
# File 'lib/zold/commands/remote.rb', line 43

def initialize(remotes:, farm: Farm::Empty.new, log: Log::Quiet.new)
  @remotes = remotes
  @farm = farm
  @log = log
end

Instance Method Details

#run(args = []) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/zold/commands/remote.rb', line 49

def run(args = [])
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
    o.banner = "Usage: zold remote <command> [options]
Available commands:
#{Rainbow('remote show').green}
  Show all registered remote nodes
#{Rainbow('remote clean').green}
  Remove all registered remote nodes
#{Rainbow('remote reset').green}
  Restore it back to the default list of nodes
#{Rainbow('remote add').green} host [port]
  Add a new remote node
#{Rainbow('remote remove').green} host [port]
  Remove the remote node
#{Rainbow('remote elect').green}
  Pick a random remote node as a target for a bonus awarding
#{Rainbow('remote trim').green}
  Remote the least reliable nodes
#{Rainbow('remote update').green}
  Check each registered remote node for availability
Available options:"
    o.bool '--ignore-score-weakness',
      'Don\'t complain when their score is too weak',
      default: false
    o.bool '--ignore-score-value',
      'Don\'t complain when their score is too small',
      default: false
    o.bool '--force',
      'Add/remove if if this operation is not possible',
      default: false
    o.bool '--skip-ping',
      'Don\'t ping back the node when adding it (not recommended)',
      default: false
    o.string '--network',
      "The name of the network we work in (default: #{Wallet::MAIN_NETWORK}",
      required: true,
      default: Wallet::MAIN_NETWORK
    o.bool '--reboot',
      'Exit if any node reports version higher than we have',
      default: false
    o.bool '--help', 'Print instructions'
  end
  mine = Args.new(opts, @log).take || return
  command = mine[0]
  raise "A command is required, try 'zold remote --help'" unless command
  case command
  when 'show'
    show
  when 'clean'
    clean
  when 'reset'
    reset
  when 'add'
    add(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
  when 'remove'
    remove(mine[1], mine[2] ? mine[2].to_i : Remotes::PORT, opts)
  when 'elect'
    elect(opts)
  when 'trim'
    trim(opts)
  when 'update'
    update(opts)
    update(opts, false)
  else
    raise "Unknown command '#{command}'"
  end
end