Skip to content

Commit 15a6ba5

Browse files
author
梶塚太智
committed
Update main.rs
1 parent f958c6a commit 15a6ba5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::collections::HashMap;
55
use std::env;
66
use std::fs::{self, File};
77
use std::io::{self, Error, Read, Write};
8+
use sys_info::{cpu_num, cpu_speed, os_release};
89
use std::path::Path;
910
use std::thread::{self, sleep};
1011
use std::time::{Duration, SystemTime, UNIX_EPOCH};
@@ -1097,6 +1098,17 @@ impl Executor {
10971098
self.stack.push(Type::Bool(path.is_dir()));
10981099
}
10991100

1101+
// Get system information
1102+
"sys-info" => {
1103+
let types = self.pop_stack().get_string();
1104+
self.stack.push(match types.as_str() {
1105+
"os-release" => Type::String(os_release().unwrap_or("".to_string())),
1106+
"cpu-num" => Type::Number(cpu_num().unwrap_or(0) as f64),
1107+
"cpu-speed" => Type::Number(cpu_speed().unwrap_or(0) as f64),
1108+
_ => Type::Error("sys-info".to_string())
1109+
})
1110+
}
1111+
11001112
// If it is not recognized as a command, use it as a string.
11011113
_ => self.stack.push(Type::String(command)),
11021114
}

0 commit comments

Comments
 (0)