lib/zold/commands/remote.rb in zold-0.10.7 vs lib/zold/commands/remote.rb in zold-0.10.8
- old
+ new
@@ -17,10 +17,11 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
require 'slop'
+require 'semantic'
require 'rainbow'
require 'net/http'
require 'json'
require 'time'
require_relative 'args'
@@ -59,10 +60,13 @@
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 '--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]
case command
@@ -123,9 +127,13 @@
score = Score.parse_json(json['score'])
r.assert_valid_score(score)
raise "Score too weak: #{score.strength}" if score.strength < Score::STRENGTH && !opts['ignore-score-weakness']
raise "Masqueraded as #{score.host}:#{score.port}" if r.host != score.host || r.port != score.port
@remotes.rescore(score.host, score.port, score.value)
+ if opts['reboot'] && Semantic::Version.new(VERSION) < Semantic::Version.new(json['version'])
+ @log.info("#{r}: their version #{json['version']} is higher than mine #{VERSION}, reboot!")
+ exit(0)
+ end
if deep
json['all'].each do |s|
add(s['host'], s['port']) unless @remotes.exists?(s['host'], s['port'])
end
end