mirror of
https://github.com/encounter/ghidra-cli.git
synced 2026-07-10 03:18:56 -07:00
style: fix clippy warnings and cargo fmt formatting
- Replace redundant closure with function reference (clippy::redundant_closure) - Use is_some_and instead of map_or(false, ...) (clippy::unnecessary_map_or) - Run cargo fmt across all files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
31bbefee33
commit
e26634c03c
+7
-1
@@ -54,7 +54,13 @@ pub enum Commands {
|
||||
Memory(MemoryCommands),
|
||||
|
||||
/// Cross-reference operations
|
||||
#[command(subcommand, alias = "xrefs", alias = "xref", alias = "crossref", alias = "crossrefs")]
|
||||
#[command(
|
||||
subcommand,
|
||||
alias = "xrefs",
|
||||
alias = "xref",
|
||||
alias = "crossref",
|
||||
alias = "crossrefs"
|
||||
)]
|
||||
XRef(XRefCommands),
|
||||
|
||||
/// Type operations
|
||||
|
||||
+11
-7
@@ -43,7 +43,6 @@ impl OutputFormat {
|
||||
_ => Err(GhidraError::InvalidFormat(format!("Unknown format: {}", s))),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub trait Formatter {
|
||||
@@ -206,14 +205,11 @@ fn format_compact<T: Serialize>(data: &[T]) -> Result<String> {
|
||||
map.get("address").and_then(|v| v.as_str()),
|
||||
map.get("mnemonic").and_then(|v| v.as_str()),
|
||||
) {
|
||||
let bytes = map
|
||||
.get("bytes")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
let bytes = map.get("bytes").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let operands = match map.get("operands") {
|
||||
Some(JsonValue::Array(ops)) => ops
|
||||
.iter()
|
||||
.map(|o| format_json_value(o))
|
||||
.map(format_json_value)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
_ => String::new(),
|
||||
@@ -269,7 +265,15 @@ fn format_compact<T: Serialize>(data: &[T]) -> Result<String> {
|
||||
.filter(|(k, _)| {
|
||||
!matches!(
|
||||
k.as_str(),
|
||||
"address" | "name" | "size" | "value" | "mnemonic" | "bytes" | "operands" | "code" | "signature"
|
||||
"address"
|
||||
| "name"
|
||||
| "size"
|
||||
| "value"
|
||||
| "mnemonic"
|
||||
| "bytes"
|
||||
| "operands"
|
||||
| "code"
|
||||
| "signature"
|
||||
)
|
||||
})
|
||||
.filter_map(|(k, v)| {
|
||||
|
||||
@@ -412,4 +412,3 @@ pub fn find_headless_script(ghidra_install_dir: &Path) -> Result<PathBuf> {
|
||||
anyhow::bail!("analyzeHeadless not found at: {}", support_dir.display())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -28,8 +28,7 @@ impl GhidraClient {
|
||||
}
|
||||
|
||||
pub fn verify_installation(&self) -> Result<()> {
|
||||
bridge::find_headless_script(&self.install_dir)
|
||||
.map_err(|_| GhidraError::GhidraNotFound)?;
|
||||
bridge::find_headless_script(&self.install_dir).map_err(|_| GhidraError::GhidraNotFound)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+10
-17
@@ -505,11 +505,7 @@ fn run_with_bridge(cli: Cli) -> anyhow::Result<()> {
|
||||
if !cli.quiet {
|
||||
eprintln!("Starting Ghidra bridge...");
|
||||
}
|
||||
let port = bridge::ensure_bridge_running(
|
||||
&project_path,
|
||||
&ghidra_install_dir,
|
||||
mode,
|
||||
)?;
|
||||
let port = bridge::ensure_bridge_running(&project_path, &ghidra_install_dir, mode)?;
|
||||
if !cli.quiet {
|
||||
eprintln!("Bridge ready.");
|
||||
}
|
||||
@@ -519,10 +515,7 @@ fn run_with_bridge(cli: Cli) -> anyhow::Result<()> {
|
||||
// Switch to requested program if it differs from the bridge's current program
|
||||
if let Some(requested_program) = extract_program_from_command(&cli.command) {
|
||||
if let Ok(info) = client.program_info() {
|
||||
let current = info
|
||||
.get("name")
|
||||
.and_then(|n| n.as_str())
|
||||
.unwrap_or("");
|
||||
let current = info.get("name").and_then(|n| n.as_str()).unwrap_or("");
|
||||
if current != requested_program {
|
||||
client.open_program(&requested_program)?;
|
||||
}
|
||||
@@ -554,7 +547,7 @@ fn run_with_bridge(cli: Cli) -> anyhow::Result<()> {
|
||||
fmt
|
||||
} else if cli.pretty {
|
||||
OutputFormat::Json
|
||||
} else if cli.json || opts.as_ref().map_or(false, |o| o.json) {
|
||||
} else if cli.json || opts.as_ref().is_some_and(|o| o.json) {
|
||||
OutputFormat::JsonCompact
|
||||
} else {
|
||||
auto_detect_format(std::io::stdout().is_terminal())
|
||||
@@ -1157,9 +1150,9 @@ fn handle_config_command(cmd: cli::ConfigCommands) -> anyhow::Result<()> {
|
||||
"default_program" => config.default_program = Some(value),
|
||||
"default_project" => config.default_project = Some(value),
|
||||
"default_limit" => {
|
||||
let limit: usize = value.parse().map_err(|_| {
|
||||
GhidraError::ConfigError("Invalid limit value".to_string())
|
||||
})?;
|
||||
let limit: usize = value
|
||||
.parse()
|
||||
.map_err(|_| GhidraError::ConfigError("Invalid limit value".to_string()))?;
|
||||
config.default_limit = Some(limit);
|
||||
}
|
||||
_ => {
|
||||
@@ -1250,13 +1243,11 @@ fn handle_project_command(cmd: cli::ProjectCommands) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
/// Check if a decompile result looks like .NET managed code and warn the user.
|
||||
fn check_dotnet_decompile_warning(command: &Commands, result: &serde_json::Value) {
|
||||
let is_decompile = matches!(
|
||||
command,
|
||||
Commands::Decompile(_)
|
||||
| Commands::Function(cli::FunctionCommands::Decompile(_))
|
||||
Commands::Decompile(_) | Commands::Function(cli::FunctionCommands::Decompile(_))
|
||||
);
|
||||
if !is_decompile {
|
||||
return;
|
||||
@@ -1330,7 +1321,9 @@ fn unwrap_bridge_response(value: serde_json::Value) -> Vec<serde_json::Value> {
|
||||
for &key in ARRAY_KEYS {
|
||||
if let Some(serde_json::Value::Array(arr)) = obj.get(key) {
|
||||
// Verify remaining keys are metadata
|
||||
let all_meta = obj.keys().all(|k| k == key || META_KEYS.contains(&k.as_str()));
|
||||
let all_meta = obj
|
||||
.keys()
|
||||
.all(|k| k == key || META_KEYS.contains(&k.as_str()));
|
||||
if all_meta {
|
||||
return arr.clone();
|
||||
}
|
||||
|
||||
+2
-6
@@ -90,11 +90,7 @@ impl Query {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let filter = opts
|
||||
.filter
|
||||
.as_ref()
|
||||
.map(|f| Filter::parse(f))
|
||||
.transpose()?;
|
||||
let filter = opts.filter.as_ref().map(|f| Filter::parse(f)).transpose()?;
|
||||
let fields = opts
|
||||
.fields
|
||||
.as_ref()
|
||||
@@ -107,7 +103,7 @@ impl Query {
|
||||
filter,
|
||||
fields,
|
||||
format,
|
||||
limit: None, // limit/offset already handled by bridge
|
||||
limit: None, // limit/offset already handled by bridge
|
||||
offset: None,
|
||||
sort,
|
||||
count_only: has_count,
|
||||
|
||||
@@ -239,4 +239,3 @@ fn test_import_existing_program() {
|
||||
.assert()
|
||||
.success();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user