1use crate::git;
2
3pub fn user() -> Result<String, String> {
5 if let Ok(user) = git::git_stdout(&["config", "wip.user"])
7 && !user.is_empty()
8 {
9 return Ok(user);
10 }
11
12 let name = git::git_stdout(&["config", "user.name"])
13 .map_err(|_| "could not determine user: set git user.name or wip.user".to_string())?;
14
15 if name.is_empty() {
16 return Err("could not determine user: set git user.name or wip.user".to_string());
17 }
18
19 Ok(slugify(&name))
20}
21
22pub fn default_expire() -> String {
24 git::git_stdout(&["config", "wip.expire"]).unwrap_or_else(|_| "30d".to_string())
25}
26
27fn slugify(s: &str) -> String {
28 s.to_lowercase()
29 .chars()
30 .map(|c| {
31 if c.is_alphanumeric() || c == '-' {
32 c
33 } else {
34 '-'
35 }
36 })
37 .collect::<String>()
38 .trim_matches('-')
39 .to_string()
40}