diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-19 23:14:30 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2021-05-19 23:14:30 +0100 |
commit | cc4da2237f5fab45ac22563f50a14f7861212693 (patch) | |
tree | 9500a17f0e7d356363d4108ee3aece4b4764b1c0 /subplotlib | |
parent | e762e23a9ac7b36c6abfc8c45d1b48407263007f (diff) | |
download | subplot-cc4da2237f5fab45ac22563f50a14f7861212693.tar.gz |
subplotlib: Add running in a subdir to runcmd
This adds the bindings and step implementations for running
commands in a directory off the datadir.
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'subplotlib')
-rw-r--r-- | subplotlib/src/steplibrary/runcmd.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/subplotlib/src/steplibrary/runcmd.rs b/subplotlib/src/steplibrary/runcmd.rs index 383f9e3..7075b68 100644 --- a/subplotlib/src/steplibrary/runcmd.rs +++ b/subplotlib/src/steplibrary/runcmd.rs @@ -38,6 +38,9 @@ static DEFAULT_PATHS: &[&str] = &[ r"%SystemRoot%\System32\Wbem", ]; +// This us used internally to force CWD for running commands +const USE_CWD: &str = "\0USE_CWD"; + impl ContextElement for Runcmd { fn scenario_starts(&mut self) -> StepResult { self.env.drain(); @@ -87,7 +90,22 @@ pub fn run(context: &ScenarioContext, argv0: &str, args: &str) { #[step] #[context(Datadir)] #[context(Runcmd)] +pub fn run_in(context: &ScenarioContext, dirname: &str, argv0: &str, args: &str) { + try_to_run_in::call(context, dirname, argv0, args)?; + exit_code_is::call(context, 0)?; +} + +#[step] +#[context(Datadir)] +#[context(Runcmd)] pub fn try_to_run(context: &ScenarioContext, argv0: &str, args: &str) { + try_to_run_in::call(context, USE_CWD, argv0, args)?; +} + +#[step] +#[context(Datadir)] +#[context(Runcmd)] +pub fn try_to_run_in(context: &ScenarioContext, dirname: &str, argv0: &str, args: &str) { // This is the core of runcmd and is how we handle things let argv0: PathBuf = if argv0.starts_with('.') { context.with( @@ -97,10 +115,13 @@ pub fn try_to_run(context: &ScenarioContext, argv0: &str, args: &str) { } else { argv0.into() }; - let datadir = context.with( + let mut datadir = context.with( |datadir: &Datadir| Ok(datadir.base_path().to_path_buf()), false, )?; + if dirname != USE_CWD { + datadir = datadir.join(dirname); + } let mut proc = Command::new(argv0); proc.args(&shell_words::split(args)?); proc.current_dir(&datadir); |