diff options
| author | 2026-02-26 22:24:15 -0500 | |
|---|---|---|
| committer | 2026-02-26 22:24:15 -0500 | |
| commit | 8c9b627d7449a53238631ec01cfcb5f778fd4e5c (patch) | |
| tree | 65ad6e1c63f3ef8256bb9914ea727723ac19c0d1 | |
| parent | begin permissions shift for build commands (diff) | |
add version flag
| -rw-r--r-- | src/action.rs | 16 | ||||
| -rw-r--r-- | src/config.rs | 25 | ||||
| -rw-r--r-- | src/util.rs | 20 |
3 files changed, 19 insertions, 42 deletions
diff --git a/src/action.rs b/src/action.rs index 58effbe..fe405a3 100644 --- a/src/action.rs +++ b/src/action.rs @@ -17,6 +17,7 @@ pub enum Action { Search { term: String }, Clean { packages: Vec<String> }, Show { package: String }, + Version, } impl Action { @@ -56,6 +57,7 @@ impl Action { let package = args.get(2).ok_or("show requires <package>")?.clone(); Ok(Action::Show { package }) } + "--version" => Ok(Action::Version), _ => Err(format!("unknown command {}", cmd)), } } @@ -71,6 +73,7 @@ impl Action { Action::Search { term } => Ok(search(term)), Action::Clean { packages } => Ok(clean(packages)), Action::Show { package } => Ok(show(package)), + Action::Version => Ok(version()), } } } @@ -217,3 +220,16 @@ fn clean(packages: Vec<String>) { fn show(package: String) { println!("showing {}", package); } + +fn version() { + println!( + r#" +.-------..___ Forge v{} +'-._ :_.-' Copyright (C) 2026 Lance Borden + ) _ ( + '-' '-' This program is free software + under the MIT license. + "#, + env!("CARGO_PKG_VERSION") + ); +} diff --git a/src/config.rs b/src/config.rs index 4976af3..ecada2a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,8 @@ use serde::Deserialize; use std::fs; -use std::os::unix::process::CommandExt; use std::path::{Path, PathBuf}; use std::process::Command; -use crate::util::get_invoking_user_env; - pub const TEMP_CONFIG_PATH: &str = "/var/lib/forge/.tmp"; pub enum ConfigCommand { @@ -70,8 +67,6 @@ pub fn run_config_command( ) -> Result<(), String> { let config = Config::new(config_path).ok_or("config not found".to_string())?; - let is_build = matches!(command, ConfigCommand::Build); - let cmd = match command { ConfigCommand::Build => config.build, ConfigCommand::Install => config.install, @@ -83,23 +78,9 @@ pub fn run_config_command( let cmd_base = parts.next().ok_or("empty command".to_string())?; let args: Vec<&str> = parts.collect(); - let mut command = Command::new(cmd_base); - command.args(&args).current_dir(repo_path); - - if is_build { - if let Some((uid, gid, home, path)) = get_invoking_user_env() { - command.env("HOME", home).env("PATH", path); - unsafe { - command.pre_exec(move || { - nix::unistd::setgid(nix::unistd::Gid::from_raw(gid))?; - nix::unistd::setuid(nix::unistd::Uid::from_raw(uid))?; - Ok(()) - }); - } - } - } - - let status = command + let status = Command::new(cmd_base) + .args(&args) + .current_dir(repo_path) .status() .map_err(|e| format!("failed to execute command: {}", e))?; diff --git a/src/util.rs b/src/util.rs index e79124d..6f04573 100644 --- a/src/util.rs +++ b/src/util.rs @@ -27,26 +27,6 @@ pub fn get_editor() -> String { .unwrap_or_else(|_| "nano".to_string()) } -pub fn get_invoking_user_env() -> Option<(u32, u32, String, String)> { - let username = std::env::var("SUDO_USER").ok()?; - if username.is_empty() { - return None; - } - - let user = nix::unistd::User::from_name(&username).ok()??; - let uid = user.uid.as_raw(); - let gid = user.gid.as_raw(); - let home = user.dir.to_string_lossy().to_string(); - - // Reconstruct a sane PATH for the user including common tool locations - let path = format!( - "{home}/.cargo/bin:{home}/.local/bin:/usr/local/bin:/usr/bin:/bin", - home = home - ); - - Some((uid, gid, home, path)) -} - pub fn open_in_editor(editor: &str, file: &str) -> Result<(), String> { let status = Command::new(editor) .arg(file) |
