Skip to content

Commit

Permalink
feat: filter tags by CLI parameter (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
oyarsa authored Jan 15, 2025
1 parent 8877cd6 commit 8bd1535
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Parser;
use std::path::PathBuf;
use std::{collections::HashSet, path::PathBuf};

use crate::{input, parser, render};

Expand All @@ -14,6 +14,10 @@ pub struct Cli {
/// Output format
#[arg(short, long, value_enum, default_value = "json")]
pub format: OutputFormat,

/// Comma-separated list of tags to show
#[arg(long, value_delimiter = ',')]
pub tags: Vec<String>,
}

impl Cli {
Expand All @@ -32,11 +36,22 @@ impl Cli {
let file_type = input::determine_file_type(&self.path)?;
annotations = parser::extract_annotations(&content, &file_type, &self.path)?;
}

let tags: HashSet<String> = self.tags.iter().cloned().collect();
let filtered_annotations = if !self.tags.is_empty() {
annotations
.into_iter()
.filter(|ann| tags.contains(&ann.kind))
.collect()
} else {
annotations
};

let output_format = match self.format {
OutputFormat::Json => render::RenderAdapter::Json(render::JsonAdapter),
OutputFormat::Yaml => render::RenderAdapter::Yaml(render::YamlAdapter),
};
let output = output_format.format(&annotations)?;
let output = output_format.format(&filtered_annotations)?;
println!("{}", output);
Ok(())
}
Expand Down

0 comments on commit 8bd1535

Please sign in to comment.