]> gitweb.fluxo.info Git - leap/leap_cli.git/commitdiff
better checking of valid node names
authorelijah <elijah@riseup.net>
Mon, 24 Mar 2014 17:32:56 +0000 (10:32 -0700)
committerelijah <elijah@riseup.net>
Mon, 24 Mar 2014 17:32:56 +0000 (10:32 -0700)
lib/leap_cli/commands/node.rb

index a4c0d1a2a26400f32fa67f1a41f64a19a0c53605..5f5c4b800271632fee02088f0f995bab9d9e0654 100644 (file)
@@ -22,12 +22,7 @@ module LeapCli; module Commands
       add.action do |global_options,options,args|
         # argument sanity checks
         name = args.first
-        assert! name, 'No <node-name> 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 <node-name> 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