diff src/command.rs @ 20:da4858f4658d

impl define cmd
author AnaTofuZ <k198584@ie.u-ryukyu.ac.jp>
date Tue, 03 Nov 2020 17:21:27 +0900
parents d37203a877d9
children 9f3d29b8561a
line wrap: on
line diff
--- a/src/command.rs	Tue Nov 03 11:10:24 2020 +0900
+++ b/src/command.rs	Tue Nov 03 17:21:27 2020 +0900
@@ -11,7 +11,10 @@
 }
 
 pub fn define(user_name: &'static str, vm_name: String) {
-    xml::generate();
+    let vm_name = generate_vm_name(user_name, &vm_name);
+    let vm_arg = xml::GenerateVMArg::new(user_name, vm_name, false);
+    vm_arg.generate().ok();
+    exec_cmd_from_name_or_id(user_name, &vm_name, "define")
 }
 
 pub fn start(user_name: &'static str, vm_name: String) {
@@ -88,3 +91,11 @@
     }
     format!("{}-{}", user_name, vm_name)
 }
+
+
+fn generate_vm_name(user_name:&'static str, vm_name: &str) -> String {
+    if vm_name.starts_with(user_name) {
+        return vm_name.to_string();
+    }
+    format!("{}-{}", user_name, vm_name)
+}
\ No newline at end of file