Onset: version control where nobody waits and nothing gets lost. The on command, its core and onset-server.
| 5 |
| 6 | /// `ONSET_<name>`, or `VCS_<name>` as it was called before Onset had its name (empty counts as unset). |
| 7 | pub fn var_os(name: &str) -> Option<OsString> { |
| 8 | let set = |v: String| std::env::var_os(v).filter(|v| !v.is_empty()); |
| 9 | set(format!("ONSET_{name}")).or_else(|| set(format!("VCS_{name}"))) |
| 10 | } |
| 11 |
| 12 | /// [`var_os`] as text. |
| 13 | pub fn var(name: &str) -> Option<String> { |
| 14 | var_os(name).and_then(|v| v.into_string().ok()) |
| 15 | } |
| 16 |
| 17 | /// ONSET_HOME, else the platform's data folder (~/.local/share/onset on |
| 18 | /// Linux, ~/Library/Application Support/onset on macOS, %LOCALAPPDATA%\onset |
| 19 | /// on Windows). A machine that used it as vcs keeps its folder of that name. |
| 20 | pub fn home() -> PathBuf { |
| 21 | if let Some(dir) = var_os("HOME") { |
| 22 | return PathBuf::from(dir); |
| 23 | } |
| 24 | let data = if cfg!(windows) |
| 25 | && let Some(local) = std::env::var_os("LOCALAPPDATA").filter(|d| !d.is_empty()) |
| 26 | { |
| 27 | PathBuf::from(local) |
| 28 | } else { |
| 29 | let user = crate::sys::user_home().unwrap_or_else(|| ".".into()); |
| 30 | if cfg!(target_os = "macos") { |
| 31 | user.join("Library/Application Support") |
| 32 | } else { |
| 33 | match std::env::var_os("XDG_DATA_HOME") { |
| 34 | Some(d) if !d.is_empty() => PathBuf::from(d), |
| 35 | _ => user.join(".local/share"), |
| 36 | } |
| 37 | } |
| 38 | }; |
| 39 | let (new, old) = (data.join("onset"), data.join("vcs")); |
| 40 | if !new.exists() && old.join("vcs.db").exists() { old } else { new } |
| 41 | } |
| 42 |
| 43 | pub fn objects() -> PathBuf { |
| 44 | home().join("objects") |
| 45 | } |
| 46 |
| 47 | /// Sign-in tokens, readable only by the user. |
| 48 | pub fn credentials() -> PathBuf { |
| 49 | home().join("credentials.json") |
| 50 | } |
| 51 |