Skip to content

Commit

Permalink
Enable multiple input files (#20)
Browse files Browse the repository at this point in the history
Closes #19

---------

Co-authored-by: Karol Sewiło <95349104+ksew1@users.noreply.github.com>
  • Loading branch information
ddoktorski and ksew1 authored Aug 26, 2024
1 parent 1466cc0 commit d4261e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
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").into());

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

0 comments on commit d4261e7

Please sign in to comment.