Skip to content

Commit

Permalink
frontend: pass unknown subcommands to python CLI (#55)
Browse files Browse the repository at this point in the history
* rust code to passthrough unknown subcommands

* make probe-py avalible to probe frontend wrapper
  • Loading branch information
Ex-32 authored Sep 18, 2024
1 parent 38659bc commit f0a2df5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
makeWrapper \
${self.packages.${system}.probe-cli}/bin/probe \
$out/bin/probe \
--set __PROBE_LIB ${libprobe}/lib
--set __PROBE_LIB ${libprobe}/lib \
--prefix PATH : ${probe-py}/bin
'';
};
probe-py-manual = python.pkgs.buildPythonPackage rec {
Expand All @@ -96,6 +97,7 @@
];
pythonImportsCheck = [pname];
};
probe-py = python.withPackages (pypkgs: [probe-py-manual]);
default = probe-bundled;
}
// frontend.packages;
Expand Down
24 changes: 23 additions & 1 deletion probe_src/frontend/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn main() -> Result<()> {
let matches = command!()
.about("Generate or manipulate Provenance for Replay OBservation Engine (PROBE) logs.")
.propagate_version(true)
.allow_external_subcommands(true)
.subcommands([
Command::new("record")
.args([
Expand Down Expand Up @@ -142,7 +143,28 @@ fn main() -> Result<()> {

Err(e).wrap_err("Shim failed to exec")
}
Some((subcommand, args)) => {
let args = args
.get_many::<OsString>("")
.unwrap()
.cloned()
.collect::<Vec<_>>();

let exit = std::process::Command::new("python3")
.arg("-m")
.arg("probe_py.manual.cli")
.arg(subcommand)
.args(&args)
.spawn()
.wrap_err("Unknown subcommand")?
.wait()
.wrap_err("Wait on subcommand failed")?;

match exit.success() {
true => Ok(()),
false => Err(eyre!("Subcommand exited with code: {}", exit)),
}
}
None => Err(eyre!("Subcommand expected, try --help for more info")),
_ => Err(eyre!("Unknown subcommand")),
}
}

0 comments on commit f0a2df5

Please sign in to comment.