Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable multiple input files #20

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions crates/cairo-coverage/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ use anyhow::{ensure, Result};
use camino::Utf8PathBuf;
use clap::Parser;

pub const DEFAULT_OUTPUT_NAME: &str = "coverage";

#[derive(Parser, Debug)]
#[command(version)]
pub struct Cli {
/// Path to the .json file with trace data.
#[arg(value_parser = parse_trace_file)]
pub trace_file: Utf8PathBuf,
/// Paths to the .json files with trace data.
#[arg(value_parser = parse_trace_file, num_args = 1..)]
pub trace_files: Vec<Utf8PathBuf>,

/// Path to the output file. [default: `<TRACE_NAME>.lcov`]
/// Path to the output file. [default: `coverage.lcov`]
#[arg(short, long)]
pub output_path: Option<Utf8PathBuf>,
}
Expand Down
8 changes: 4 additions & 4 deletions crates/cairo-coverage/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod cli;

use crate::cli::DEFAULT_OUTPUT_NAME;
use anyhow::{Context, Result};
use clap::Parser;
use cli::Cli;
Expand All @@ -9,10 +10,9 @@ use std::io::Write;
fn main() -> Result<()> {
let cli = Cli::parse();

let output_path = cli.output_path.unwrap_or_else(|| {
let output_file_name = cli.trace_file.file_stem().unwrap(); // Safe to unwrap since we checked that the file exists
format!("./{output_file_name}.lcov").into()
});
let output_path = cli
.output_path
.unwrap_or_else(|| format!("./{DEFAULT_OUTPUT_NAME}.lcov").to_string().into());
ddoktorski marked this conversation as resolved.
Show resolved Hide resolved

File::create(&output_path)
.context(format!(
Expand Down
Loading