changeset 9:b89466455757

not parse when executing the list command
author AnaTofuZ <anatofuz@gmail.com>
date Wed, 28 Oct 2020 17:35:12 +0900
parents 017344e337e8
children 188bf8ab3e81
files src/main.rs
diffstat 1 files changed, 12 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.rs	Wed Oct 28 17:02:09 2020 +0900
+++ b/src/main.rs	Wed Oct 28 17:35:12 2020 +0900
@@ -57,10 +57,10 @@
 
         SubCommand::list(list) => {
             set_root_id();
-            let (vm_list, list_dump_msg) = list_command(user_name);
-            println!("{}\n{}", list_dump_msg.info_msg, list_dump_msg.border_line);
-            for vm in vm_list.iter() {
-                println!("{} {}", vm.id, vm.name);
+            let (ldump_msg, vm_list_strs) = list_command(user_name);
+            println!("{}\n{}", ldump_msg.info_msg, ldump_msg.border_line);
+            for vm_info in vm_list_strs {
+                println!("{}", vm_info);
             }
         }
     }
@@ -86,7 +86,7 @@
     return gid_struct.into();
 }
 
-fn list_command(user_name: &'static str) -> (Vec<VM>, list_dump_msg) {
+fn list_command(user_name: &'static str) -> (list_dump_msg, Vec<String>) {
     let output = Command::new("virsh")
         .arg("list")
         .arg("--all")
@@ -102,26 +102,13 @@
         border_line: String::from(border_line),
     };
 
-    let virsh_emit_vm_list = virsh_list.filter(|&x| x.contains(user_name));
-
-    let mut vm_list: Vec<VM> = Vec::new();
-
-    for emit_vm in virsh_emit_vm_list {
-        let mut vm_infos = emit_vm.split_whitespace();
-        let vm_status = vm_infos.next().unwrap();
-        let (is_vm_running, id) = if vm_status != "-" {
-            (true, vm_status)
-        } else {
-            (false, "0")
-        };
-        let name = vm_infos.next().unwrap();
-        vm_list.push(VM {
-            id: id.parse().unwrap(),
-            is_vm_running: is_vm_running,
-            name: String::from(name),
-        });
-    }
-    return (vm_list, ldump_msg);
+    return (
+        ldump_msg,
+        virsh_list
+            .filter(|&x| x.contains(user_name))
+            .map(|x| x.to_string())
+            .collect(),
+    );
 }
 
 fn set_root_id() {