diamond-in commited on
Commit
89b790c
·
verified ·
1 Parent(s): 4563a46

Update src/agent/executor.rs

Browse files
Files changed (1) hide show
  1. src/agent/executor.rs +16 -10
src/agent/executor.rs CHANGED
@@ -1,14 +1,20 @@
1
  use std::process::Command;
2
 
3
- pub fn run_in_nix(cmd: &str, packages: Vec<&str>) -> String {
4
- let pkgs = packages.join(" ");
5
- let output = Command::new("nix-shell")
6
- .arg("-p")
7
- .arg(pkgs)
8
- .arg("--run")
9
- .arg(cmd)
10
- .output()
11
- .expect("failed to execute nix command");
12
 
13
- String::from_utf8_lossy(&output.stdout).to_string()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
 
1
  use std::process::Command;
2
 
3
+ pub struct NixExecutor;
 
 
 
 
 
 
 
 
4
 
5
+ impl NixExecutor {
6
+ pub fn execute(cmd: &str, packages: Vec<&str>) -> String {
7
+ // This runs the command inside a nix-shell with the requested packages
8
+ let mut nix_cmd = Command::new("nix-shell");
9
+ nix_cmd.arg("-p").args(packages).arg("--run").arg(cmd);
10
+
11
+ match nix_cmd.output() {
12
+ Ok(output) => {
13
+ let stdout = String::from_utf8_lossy(&output.stdout);
14
+ let stderr = String::from_utf8_lossy(&output.stderr);
15
+ format!("STDOUT: {}\nSTDERR: {}", stdout, stderr)
16
+ }
17
+ Err(e) => format!("Failed to execute Nix command: {}", e),
18
+ }
19
+ }
20
  }