aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-05-15 14:43:43 -0700
committerelijah <elijah@riseup.net>2013-05-15 14:43:43 -0700
commitd0ffb032025d54698abc6dde86fcf36770a5b1ca (patch)
tree4a00e81225f6de969e2145f7945e7bb0753fe51a
parent37130be91eb463ddd8a626091cb49a09a15bfbc2 (diff)
downloadleap_cli-d0ffb032025d54698abc6dde86fcf36770a5b1ca.tar.gz
leap_cli-d0ffb032025d54698abc6dde86fcf36770a5b1ca.tar.bz2
better parsing of `leap node add` (fixes #2531)
-rw-r--r--lib/leap_cli/commands/node.rb28
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb
index 4c7230c..f34b55a 100644
--- a/lib/leap_cli/commands/node.rb
+++ b/lib/leap_cli/commands/node.rb
@@ -186,9 +186,7 @@ module LeapCli; module Commands
def seed_node_data(node, args)
args.each do |seed|
key, value = seed.split(':')
- if value =~ /,/
- value = value.split(',')
- end
+ value = format_seed_value(value)
assert! key =~ /^[0-9a-z\._]+$/, "illegal characters used in property '#{key}'"
if key =~ /\./
key_parts = key.split('.')
@@ -205,6 +203,30 @@ module LeapCli; module Commands
end
end
+ #
+ # conversations:
+ #
+ # "x,y,z" => ["x","y","z"]
+ #
+ # "22" => 22
+ #
+ # "5.1" => 5.1
+ #
+ def format_seed_value(v)
+ if v =~ /,/
+ v = v.split(',')
+ v.map do |i|
+ i = i.to_i if i.to_i.to_s == i
+ i = i.to_f if i.to_f.to_s == i
+ i
+ end
+ else
+ v = v.to_i if v.to_i.to_s == v
+ v = v.to_f if v.to_f.to_s == v
+ end
+ return v
+ end
+
def validate_ip_address(node)
IPAddr.new(node['ip_address'])
rescue ArgumentError