1use crate::utils::read_to_string;
7use anyhow::{Context, Result};
8use clap::Parser;
9use cranelift_reader::parse_functions;
10use std::path::{Path, PathBuf};
11
12#[derive(Parser)]
14pub struct Options {
15 #[arg(required = true)]
17 files: Vec<PathBuf>,
18}
19
20pub fn run(options: &Options) -> Result<()> {
21 for (i, f) in options.files.iter().enumerate() {
22 if i != 0 {
23 println!();
24 }
25 cat_one(f)?
26 }
27 Ok(())
28}
29
30fn cat_one(path: &Path) -> Result<()> {
31 let buffer = read_to_string(path)?;
32 let items =
33 parse_functions(&buffer).with_context(|| format!("failed to parse {}", path.display()))?;
34
35 for (idx, func) in items.into_iter().enumerate() {
36 if idx != 0 {
37 println!();
38 }
39 print!("{func}");
40 }
41
42 Ok(())
43}