diff --git a/.github/workflows/pr-lint.yaml b/.github/workflows/pr-lint.yaml index 41b47a771..d1e4f9c61 100644 --- a/.github/workflows/pr-lint.yaml +++ b/.github/workflows/pr-lint.yaml @@ -4,6 +4,9 @@ on: pull_request: types: - opened +``` + + - opened - edited - synchronize diff --git a/crates/cli/src/commands/list.rs b/crates/cli/src/commands/list.rs index ca89fdec6..07e7e4789 100644 --- a/crates/cli/src/commands/list.rs +++ b/crates/cli/src/commands/list.rs @@ -13,6 +13,9 @@ use crate::{ #[derive(Args, Debug, Serialize)] pub struct ListArgs { /// List only at or above an enforcement level. + /// List only items targeting a specific language. + #[clap(long = "language", alias = "lang")] + pub lang: Option, #[clap(long = "level")] pub level: Option, /// List items from a specific source. diff --git a/crates/cli/src/commands/patterns_list.rs b/crates/cli/src/commands/patterns_list.rs index 73f68ec1f..3829d4d72 100644 --- a/crates/cli/src/commands/patterns_list.rs +++ b/crates/cli/src/commands/patterns_list.rs @@ -33,9 +33,13 @@ impl Listable for ResolvedGritDefinition { normal_tags.extend(more_tags); normal_tags } -} pub(crate) async fn run_patterns_list(arg: ListArgs, parent: GlobalFormatFlags) -> Result<()> { let (resolved, curr_repo) = resolve_from_flags_or_cwd(&parent, &arg.source).await?; - list_applyables(false, false, resolved, arg.level, &parent, curr_repo).await -} + let filtered_resolved: Vec<_> = if let Some(ref lang) = arg.lang { + resolved.into_iter().filter(|pattern| pattern.language().map_or(false, |l| l == lang)).collect() + } else { + resolved + }; + list_applyables(false, false, filtered_resolved, arg.level, &parent, curr_repo).await +} \ No newline at end of file diff --git a/crates/cli_bin/tests/snapshots/apply__language_option_inline_pattern_apply.snap b/crates/cli_bin/tests/snapshots/apply__language_option_inline_pattern_apply.snap index c7b0ba948..74562810a 100644 --- a/crates/cli_bin/tests/snapshots/apply__language_option_inline_pattern_apply.snap +++ b/crates/cli_bin/tests/snapshots/apply__language_option_inline_pattern_apply.snap @@ -8,5 +8,27 @@ import os import openai from flask import Flask, redirect, render_template, request, url_for +import pytest + +def test_language_option_inline_pattern_apply(): + # Set up the test environment and arguments + args = ["grit", "patterns", "list", "--lang", "python"] + expected_patterns = ["pattern1", "pattern2"] # Example expected patterns for Python + + # Run the command with the language argument + result = run_command(args) + + # Assert that the output contains the expected patterns for the specified language + for pattern in expected_patterns: + assert pattern in result.output + +app = Flask(__name__) +openai.api_key = dotenv.fetch("OPENAI_API_KEY") +``` + + + +``` + app = Flask(__name__) openai.api_key = dotenv.fetch("OPENAI_API_KEY")