changeset 8:017344e337e8

use split_whitespace
author AnaTofuZ <anatofuz@gmail.com>
date Wed, 28 Oct 2020 17:02:09 +0900
parents 07b763b84401
children b89466455757
files src/main.rs
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.rs	Wed Oct 28 16:32:25 2020 +0900
+++ b/src/main.rs	Wed Oct 28 17:02:09 2020 +0900
@@ -1,4 +1,4 @@
-use clap::{App, Arg, Clap};
+use clap::Clap;
 use nix;
 use std::process::Command;
 
@@ -107,12 +107,16 @@
     let mut vm_list: Vec<VM> = Vec::new();
 
     for emit_vm in virsh_emit_vm_list {
-        let mut vm_infos = emit_vm.split(" ");
+        let mut vm_infos = emit_vm.split_whitespace();
         let vm_status = vm_infos.next().unwrap();
-        let is_vm_running = if vm_status != "-" { true } else { false };
+        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: 0,
+            id: id.parse().unwrap(),
             is_vm_running: is_vm_running,
             name: String::from(name),
         });