Skip to main content

ralph_workflow/diagnostics/runtime/
mod.rs

1//! Runtime module for diagnostics - contains OS-boundary code.
2//!
3//! This module satisfies the dylint boundary-module check for code that uses
4//! std::env for system information.
5
6use std::path::PathBuf;
7
8pub use crate::executor::ProcessExecutor;
9
10/// Get the OS and architecture as a formatted string.
11pub fn get_os_info() -> String {
12    format!("{} {}", std::env::consts::OS, std::env::consts::ARCH)
13}
14
15/// Get the current working directory.
16pub fn get_working_directory() -> std::io::Result<PathBuf> {
17    std::env::current_dir()
18}
19
20/// Get the SHELL environment variable.
21pub fn get_shell() -> Option<String> {
22    std::env::var("SHELL").ok()
23}
24
25/// Get the architecture.
26pub fn get_arch() -> &'static str {
27    std::env::consts::ARCH
28}
29
30/// Check if the current directory is a git repository.
31pub fn is_git_repo(executor: &dyn ProcessExecutor) -> bool {
32    executor
33        .execute("git", &["rev-parse", "--git-dir"], &[], None)
34        .map(|o| o.status.success())
35        .unwrap_or(false)
36}
37
38/// Get the OS.
39pub fn get_os() -> &'static str {
40    std::env::consts::OS
41}