Skip to content

Commit

Permalink
Filtering and formatting parameters for dylibs command
Browse files Browse the repository at this point in the history
  • Loading branch information
Arsynth committed May 30, 2023
1 parent f13e4a5 commit 12cc691
Showing 1 changed file with 51 additions and 41 deletions.
92 changes: 51 additions & 41 deletions src/commands/dylibs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use super::common;
use super::common::Format;
use super::common::ObjectFilter;
use super::handler::*;
use super::Printer;
use super::Result;
use crate::*;
use colored::*;
use super::common::options::*;
use getopts::*;

static SUBCOMM_NAME: &str = "dylibs";

Expand All @@ -26,65 +30,71 @@ impl Handler for DylibsHandler {
SUBCOMM_NAME == name
}

fn handle_object(&self, object: ObjectType, _other_args: Vec<String>) -> Result<()> {
match object {
ObjectType::Fat(fat) => self.handle_fat(fat),
ObjectType::MachO(macho) => self.handle_macho(macho, 0),
}
Ok(())
}
}
fn handle_object(&self, object: ObjectType, other_args: Vec<String>) -> Result<()> {
let mut opts = Options::new();
self.accepted_option_items().add_to_opts(&mut opts);

impl DylibsHandler {
fn handle_fat(&self, fat: FatObject) {
for (index, arch) in fat.arch_iterator().enumerate() {
self.handle_arch(arch, index + 1);
println!("");
let format = &Format::build(&mut opts, &other_args)?;
let filter = ObjectFilter::build(&mut opts, &other_args)?;

let objects = &filter.get_objects(object);
let out_arch = objects.len() > 1;
for (idx, obj) in objects.iter().enumerate() {
if out_arch {
common::out_single_arch_title(&self.printer, &obj.header(), idx, format.short);
}
self.handle_load_commands(obj.load_commands_iterator(), format);
}
}

fn handle_arch(&self, arch: FatArch, index: usize) {
let object = arch.object().unwrap();
self.handle_macho(object, index);
Ok(())
}

fn handle_macho(&self, macho: MachObject, index: usize) {
common::out_single_arch_title(&self.printer, &macho.header(), index, false);
self.handle_load_commands(macho.load_commands_iterator());
fn accepted_option_items(&self) -> Vec<common::options::OptionItem> {
let mut result = default_option_items();
result.append(&mut Format::option_items());
result
}
}

fn handle_load_commands(&self, commands: LoadCommandIterator) {
impl DylibsHandler {
fn handle_load_commands(&self, commands: LoadCommandIterator, format: &Format) {
let commands = commands.flat_map(|cmd| match cmd.variant {
LcVariant::LoadDylib(dylib) => Some(dylib),
_ => None,
});
for (index, cmd) in commands.enumerate() {
self.handle_dylib_command(cmd, index);
self.handle_dylib_command(cmd, index, format);
}
}

fn handle_dylib_command(&self, dylib: LcDylib, index: usize) {
self.printer.out_list_item_dash(0, index);
fn handle_dylib_command(&self, dylib: LcDylib, index: usize, format: &Format) {
if format.show_indices {
self.printer.out_list_item_dash(0, index);
}

let name = common::colored_path_string(dylib.name);
self.printer.print_string(name);

self.printer.print_colored_string(" (".bright_white());
self.printer.out_default_colored_field(
"Timestamp",
&dylib.timestamp.to_string(),
", ",
);
self.printer.out_default_colored_field(
"Current version",
&dylib.current_version.to_string(),
", ",
);
self.printer.out_default_colored_field(
"Compatibility version",
&dylib.compatibility_version.to_string(),
"",
);
self.printer.print_colored_string(")".bright_white());
if !format.short {
self.printer.print_colored_string(" (".bright_white());
self.printer.out_default_colored_field(
"Timestamp",
&dylib.timestamp.to_string(),
", ",
);
self.printer.out_default_colored_field(
"Current version",
&dylib.current_version.to_string(),
", ",
);
self.printer.out_default_colored_field(
"Compatibility version",
&dylib.compatibility_version.to_string(),
"",
);
self.printer.print_colored_string(")".bright_white());
}

self.printer.print_line("");
}
}

0 comments on commit 12cc691

Please sign in to comment.