lib/zold/commands/remote.rb in zold-0.16.18 vs lib/zold/commands/remote.rb in zold-0.16.19
- old
+ new
@@ -85,10 +85,13 @@
'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.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)',
@@ -175,9 +178,13 @@
end
def add(host, port, opts)
if opts['ignore-node'].include?("#{host}:#{port}")
@log.info("#{host}:#{port} won't be added since it's in the --ignore-node list")
+ return
+ end
+ if opts['ignore-if-exists'] && @remotes.exists?(host, port)
+ @log.info("#{host}:#{port} already exists, won't add because of --ignore-if-exists")
return
end
unless opts['skip-ping']
res = Http.new(uri: "http://#{host}:#{port}/version", network: opts['network']).get
raise "The node #{host}:#{port} is not responding, #{res.code}:#{res.message}" unless res.code == '200'