Class: Zold::Remote
- Inherits:
-
Object
- Object
- Zold::Remote
- Includes:
- ThreadBadge
- Defined in:
- lib/zold/commands/remote.rb
Overview
Remote command
Instance Method Summary collapse
-
#initialize(remotes:, farm: Farm::Empty.new, log: Log::NULL) ⇒ Remote
constructor
A new instance of Remote.
- #run(args = []) ⇒ Object
Constructor Details
Instance Method Details
#run(args = []) ⇒ Object
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/zold/commands/remote.rb', line 56 def run(args = []) @log.debug("Remote.run(#{args.join(' ')})") opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = "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 masters').green} Add all \"master\" nodes to the list #{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} Remove the least reliable nodes #{Rainbow('remote select [options]').green} Select the most reliable N nodes #{Rainbow('remote update').green} Check each registered remote node for availability Available options:" o.integer '--tolerate', "Maximum level of errors we are able to tolerate (default: #{Remotes::TOLERANCE})", default: Remotes::TOLERANCE 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.array '--ignore-node', 'Ignore this node and never add it to the list', default: [] o.bool '--ignore-if-exists', 'Ignore the node while adding if it already exists in the list', default: false o.bool '--ignore-masters', 'Don\'t elect master nodes, only edges', default: false o.bool '--masters-too', 'Give no priviledges to masters, treat them as other nodes', default: false o.integer '--min-score', "The minimum score required for winning the election (default: #{Tax::EXACT_SCORE})", default: Tax::EXACT_SCORE o.integer '--max-winners', 'The maximum amount of election winners the election (default: 1)', default: 1 o.integer '--retry', 'How many times to retry each node before reporting a failure (default: 2)', default: 2 o.bool '--skip-ping', 'Don\'t ping back the node when adding it (not recommended)', default: false o.bool '--ignore-ping', 'Don\'t fail if ping fails, just report the problem in the log', default: false o.integer '--depth', 'The amount of update cycles to run, in order to fetch as many nodes as possible (default: 2)', default: 2 o.integer '--threads', "How many threads to use for updating, electing, etc. (default: #{[Concurrent.processor_count, 4].min})", default: [Concurrent.processor_count, 4].min o.string '--network', "The name of the network we work in (default: #{Wallet::MAINET})", required: true, default: Wallet::MAINET o.bool '--reboot', 'Exit if any node reports version higher than we have', default: false # @todo #292:30min Group options by subcommands # Having all the options in one place _rather than grouping them by subcommands_ # makes the help totally misleading and hard to read. # Not all the options are valid for every command - that's the key here. # The option below (`--max-nodes`) is an example. # **Next actions:** # - Implement the suggestion above. # - Remove note from the --max-nodes option saying that it applies to the select # subcommand only. o.integer '--max-nodes', "Number of nodes to limit to (default: #{Remotes::MAX_NODES})", default: Remotes::MAX_NODES 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(opts) when 'masters' masters(opts) 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) when 'select' select(opts) else raise "Unknown command '#{command}'" end end |