mirror of
https://github.com/encounter/ghidra-cli.git
synced 2026-07-10 03:18:56 -07:00
fix: inject --project/--program after subcommand in GhidraCommand helper
The GhidraCommand builder was adding --project before the subcommand args (e.g., `ghidra --project X function list`), but --project is a per-subcommand arg, not a global one. Now stores project/program as builder state and injects them after all other args in run(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
b72ddd1894
commit
68854a10d6
+19
-7
@@ -129,6 +129,8 @@ impl GhidraResult {
|
||||
/// Builder for running ghidra CLI commands with proper configuration.
|
||||
pub struct GhidraCommand {
|
||||
args: Vec<String>,
|
||||
project: Option<String>,
|
||||
program: Option<String>,
|
||||
env_vars: Vec<(String, String)>,
|
||||
timeout_secs: u64,
|
||||
}
|
||||
@@ -138,6 +140,8 @@ impl GhidraCommand {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
args: Vec::new(),
|
||||
project: None,
|
||||
program: None,
|
||||
env_vars: Vec::new(),
|
||||
timeout_secs: 120,
|
||||
}
|
||||
@@ -168,16 +172,16 @@ impl GhidraCommand {
|
||||
}
|
||||
|
||||
/// Configure for bridge connection.
|
||||
pub fn with_daemon(self, harness: &DaemonTestHarness) -> Self {
|
||||
self.arg("--project").arg(harness.project())
|
||||
pub fn with_daemon(mut self, harness: &DaemonTestHarness) -> Self {
|
||||
self.project = Some(harness.project().to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Set project and program arguments.
|
||||
pub fn with_project(self, project: &str, program: &str) -> Self {
|
||||
self.arg("--project")
|
||||
.arg(project)
|
||||
.arg("--program")
|
||||
.arg(program)
|
||||
pub fn with_project(mut self, project: &str, program: &str) -> Self {
|
||||
self.project = Some(project.to_string());
|
||||
self.program = Some(program.to_string());
|
||||
self
|
||||
}
|
||||
|
||||
/// Request JSON output format.
|
||||
@@ -203,6 +207,14 @@ impl GhidraCommand {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
// Add --project and --program after the subcommand and its args
|
||||
if let Some(ref project) = self.project {
|
||||
cmd.arg("--project").arg(project);
|
||||
}
|
||||
if let Some(ref program) = self.program {
|
||||
cmd.arg("--program").arg(program);
|
||||
}
|
||||
|
||||
cmd.timeout(std::time::Duration::from_secs(self.timeout_secs));
|
||||
|
||||
let output = cmd.output().expect("Failed to run ghidra command");
|
||||
|
||||
Reference in New Issue
Block a user