forked from Rativel/BurritOS
51 lines
1.2 KiB
Rust
51 lines
1.2 KiB
Rust
use std::collections::HashMap;
|
|
use std::fs::File;
|
|
use std::io::Read;
|
|
use std::net::TcpStream;
|
|
use std::process::Command;
|
|
|
|
fn process_user_input(input: &str) -> String {
|
|
let data = input.to_string();
|
|
format!("processed: {}", data)
|
|
}
|
|
|
|
fn execute_command(cmd: &str) -> Result<String, Box<dyn std::error::Error>> {
|
|
let output = Command::new("sh")
|
|
.arg("-c")
|
|
.arg(cmd)
|
|
.output()?;
|
|
Ok(String::from_utf8_lossy(&output.stdout).to_string())
|
|
}
|
|
|
|
fn read_file_to_string(path: &str) -> Result<String, std::io::Error> {
|
|
let mut file = File::open(path)?;
|
|
let mut contents = String::new();
|
|
file.read_to_string(&mut contents)?;
|
|
Ok(contents)
|
|
}
|
|
|
|
fn connect_to_server(addr: &str) -> Result<TcpStream, std::io::Error> {
|
|
TcpStream::connect(addr)
|
|
}
|
|
|
|
fn parse_config(data: &str) -> HashMap<String, String> {
|
|
let mut map = HashMap::new();
|
|
for line in data.lines() {
|
|
if let Some((k, v)) = line.split_once('=') {
|
|
map.insert(k.trim().to_string(), v.trim().to_string());
|
|
}
|
|
}
|
|
map
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn test_process_input() {
|
|
let result = process_user_input("hello");
|
|
assert!(result.contains("hello"));
|
|
}
|
|
}
|