From f305ca4688f92377b4b51af6e8674df02c18e3e2 Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 24 Mar 2014 10:32:56 -0700 Subject: better checking of valid node names --- lib/leap_cli/commands/node.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb index a4c0d1a..5f5c4b8 100644 --- a/lib/leap_cli/commands/node.rb +++ b/lib/leap_cli/commands/node.rb @@ -22,12 +22,7 @@ module LeapCli; module Commands add.action do |global_options,options,args| # argument sanity checks name = args.first - assert! name, 'No specified.' - if options[:local] - assert! name =~ /^[0-9a-z]+$/, "illegal characters used in node name '#{name}' (note: Vagrant does not allow hyphens or underscores)" - else - assert! name =~ /^[0-9a-z-]+$/, "illegal characters used in node name '#{name}' (note: Linux does not allow underscores)" - end + assert_valid_node_name!(name, options[:local]) assert_files_missing! [:node_config, name] # create and seed new node @@ -92,6 +87,7 @@ module LeapCli; module Commands mv.action do |global_options,options,args| node = get_node_from_args(args) new_name = args.last + assert_valid_node_name!(new_name, node.vagrant?) ensure_dir [:node_files_dir, new_name] Leap::Platform.node_files.each do |path| rename_file! [path, node.name], [path, new_name] @@ -276,4 +272,13 @@ module LeapCli; module Commands end end + def assert_valid_node_name!(name, local=false) + assert! name, 'No specified.' + if local + assert! name =~ /^[0-9a-z]+$/, "illegal characters used in node name '#{name}' (note: Vagrant does not allow hyphens or underscores)" + else + assert! name =~ /^[0-9a-z-]+$/, "illegal characters used in node name '#{name}' (note: Linux does not allow underscores)" + end + end + end; end \ No newline at end of file -- cgit v1.2.3