Skip to content

Commit

Permalink
feat: run Argcfile.sh without child process (sigoden#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Aug 4, 2023
1 parent 7773228 commit 6f0dc57
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 86 deletions.
29 changes: 0 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ either = "1.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
which = "4.2"
ctrlc = "3.4"
shell-words = "1.1"
textwrap = "0.16"
dirs = "5.0"
Expand Down
34 changes: 15 additions & 19 deletions src/bin/argc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ use argc::{
Shell,
};
use base64::{engine::general_purpose, Engine as _};
use std::{
collections::HashMap,
env, fs, process,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
},
};
use std::{collections::HashMap, env, fs, process};
use utils::*;
use which::which;

Expand Down Expand Up @@ -132,24 +125,27 @@ fn run() -> Result<i32> {
let shell = get_shell_path().ok_or_else(|| anyhow!("Shell not found"))?;
let (script_dir, script_file) = get_script_path(true)
.ok_or_else(|| anyhow!("Argcfile not found, try `argc --argc-help` for help."))?;
let interrupt = Arc::new(AtomicBool::new(false));
let interrupt_me = interrupt.clone();
ctrlc::set_handler(move || interrupt_me.store(true, Ordering::Relaxed))
.with_context(|| "Failed to set CTRL-C handler")?;
let mut envs = HashMap::new();
if let Some(cwd) = get_current_dir() {
envs.insert("ARGC_PWD".to_string(), escape_shell_words(&cwd));
}
let status = process::Command::new(shell)
let mut command = process::Command::new(shell);
command
.arg(&script_file)
.args(&args[1..])
.current_dir(script_dir)
.envs(envs)
.status()
.with_context(|| format!("Failed to run `{}`", script_file.display()))?;
if interrupt.load(Ordering::Relaxed) {
Ok(130)
} else {
.envs(envs);
#[cfg(unix)]
{
use std::os::unix::process::CommandExt;
let err = command.exec();
bail!("Failed to run `{err}`");
}
#[cfg(not(unix))]
{
let status = command
.status()
.with_context(|| format!("Failed to run `{}`", script_file.display()))?;
Ok(status.code().unwrap_or_default())
}
}
Expand Down
34 changes: 0 additions & 34 deletions tests/interrupt.rs

This file was deleted.

3 changes: 0 additions & 3 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ mod param_fn;
mod spec;
mod validate;
mod wrap_help;

#[cfg(unix)]
mod interrupt;

0 comments on commit 6f0dc57

Please sign in to comment.