mostro_client/util/
misc.rs

1use std::{fs, path::Path};
2
3pub fn uppercase_first(s: &str) -> String {
4    let mut c = s.chars();
5    match c.next() {
6        None => String::new(),
7        Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
8    }
9}
10
11pub fn get_mcli_path() -> String {
12    let home_dir = dirs::home_dir().expect("Couldn't get home directory");
13    let mcli_path = format!("{}/.mcli", home_dir.display());
14    if !Path::new(&mcli_path).exists() {
15        match fs::create_dir(&mcli_path) {
16            Ok(_) => println!("Directory {} created.", mcli_path),
17            Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {
18                // Directory was created by another thread/process, which is fine
19            }
20            Err(e) => panic!("Couldn't create mostro-cli directory in HOME: {}", e),
21        }
22    }
23    mcli_path
24}