clif-util: Switch to using structopt for CLI arguments

This commit is contained in:
Nick Fitzgerald
2020-09-14 16:26:02 -07:00
parent 31cbbd1d20
commit ed38348b22
13 changed files with 492 additions and 537 deletions

View File

@@ -7,9 +7,24 @@ use crate::utils::read_to_string;
use anyhow::Result;
use cranelift_codegen::cfg_printer::CFGPrinter;
use cranelift_reader::parse_functions;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
pub fn run(files: &[String]) -> Result<()> {
for (i, f) in files.iter().enumerate() {
/// Prints out cfg in GraphViz Dot format
#[derive(StructOpt)]
pub struct Options {
/// Specify an input file to be used. Use '-' for stdin.
#[structopt(required(true), parse(from_os_str))]
files: Vec<PathBuf>,
/// Enable debug output on stderr/stdout
#[structopt(short = "d")]
debug: bool,
}
pub fn run(options: &Options) -> Result<()> {
crate::handle_debug_flag(options.debug);
for (i, f) in options.files.iter().enumerate() {
if i != 0 {
println!();
}
@@ -18,8 +33,8 @@ pub fn run(files: &[String]) -> Result<()> {
Ok(())
}
fn print_cfg(filename: &str) -> Result<()> {
let buffer = read_to_string(filename)?;
fn print_cfg(path: &Path) -> Result<()> {
let buffer = read_to_string(path)?;
let items = parse_functions(&buffer)?;
for (idx, func) in items.into_iter().enumerate() {