Skip to content

Commit cdc2d93

Browse files
committed
feat(gcc): better command matching.
1 parent a6cafd1 commit cdc2d93

2 files changed

Lines changed: 64 additions & 14 deletions

File tree

src/discover/rules.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ pub const PATTERNS: &[&str] = &[
5151
r"^(?:bundle\s+exec\s+)?(?:bin/)?(?:rake|rails)\s+test",
5252
r"^(?:bundle\s+exec\s+)?rspec(?:\s|$)",
5353
r"^(?:bundle\s+exec\s+)?rubocop(?:\s|$)",
54-
// C/C++ compilers
55-
r"^(gcc|g\+\+|clang|clang\+\+)(\s|$)",
54+
// C/C++ compilers (one pattern per binary so rtk_cmd can encode the name)
55+
r"^gcc(\s|$)",
56+
r"^g\+\+(\s|$)",
57+
r"^clang(\s|$)",
58+
r"^clang\+\+(\s|$)",
5659
// AWS CLI
5760
r"^aws\s+",
5861
// PostgreSQL
@@ -383,7 +386,31 @@ pub const RULES: &[RtkRule] = &[
383386
// C/C++ compilers
384387
RtkRule {
385388
rtk_cmd: "rtk gcc",
386-
rewrite_prefixes: &["clang++", "clang", "g++", "gcc"],
389+
rewrite_prefixes: &["gcc"],
390+
category: "Build",
391+
savings_pct: 70.0,
392+
subcmd_savings: &[],
393+
subcmd_status: &[],
394+
},
395+
RtkRule {
396+
rtk_cmd: "rtk g++",
397+
rewrite_prefixes: &["g++"],
398+
category: "Build",
399+
savings_pct: 70.0,
400+
subcmd_savings: &[],
401+
subcmd_status: &[],
402+
},
403+
RtkRule {
404+
rtk_cmd: "rtk clang",
405+
rewrite_prefixes: &["clang"],
406+
category: "Build",
407+
savings_pct: 70.0,
408+
subcmd_savings: &[],
409+
subcmd_status: &[],
410+
},
411+
RtkRule {
412+
rtk_cmd: "rtk clang++",
413+
rewrite_prefixes: &["clang++"],
387414
category: "Build",
388415
savings_pct: 70.0,
389416
subcmd_savings: &[],

src/main.rs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -655,17 +655,28 @@ enum Commands {
655655
args: Vec<String>,
656656
},
657657

658-
/// gcc/g++ compiler with grouped error output (60-80% token savings)
659-
///
660-
/// Strips verbose caret/source-snippet context lines and groups
661-
/// diagnostics by file. Errors show file + line + message; warnings
662-
/// are summarised by file. Works with gcc, g++, and clang.
658+
/// gcc compiler with grouped error output (60-80% token savings)
663659
Gcc {
664-
/// Compiler binary to invoke (gcc, g++, clang, clang++)
665-
#[arg(default_value = "gcc")]
666-
compiler: String,
660+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
661+
args: Vec<String>,
662+
},
663+
664+
/// g++ compiler with grouped error output (60-80% token savings)
665+
#[command(name = "g++")]
666+
Gxx {
667+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
668+
args: Vec<String>,
669+
},
667670

668-
/// Compiler arguments (source files, flags, …)
671+
/// clang compiler with grouped error output (60-80% token savings)
672+
Clang {
673+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
674+
args: Vec<String>,
675+
},
676+
677+
/// clang++ compiler with grouped error output (60-80% token savings)
678+
#[command(name = "clang++")]
679+
Clangxx {
669680
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
670681
args: Vec<String>,
671682
},
@@ -2065,8 +2076,17 @@ fn main() -> Result<()> {
20652076
golangci_cmd::run(&args, cli.verbose)?;
20662077
}
20672078

2068-
Commands::Gcc { compiler, args } => {
2069-
gcc_cmd::run(&compiler, &args, cli.verbose)?;
2079+
Commands::Gcc { args } => {
2080+
gcc_cmd::run("gcc", &args, cli.verbose)?;
2081+
}
2082+
Commands::Gxx { args } => {
2083+
gcc_cmd::run("g++", &args, cli.verbose)?;
2084+
}
2085+
Commands::Clang { args } => {
2086+
gcc_cmd::run("clang", &args, cli.verbose)?;
2087+
}
2088+
Commands::Clangxx { args } => {
2089+
gcc_cmd::run("clang++", &args, cli.verbose)?;
20702090
}
20712091

20722092
Commands::HookAudit { since } => {
@@ -2289,6 +2309,9 @@ fn is_operational_command(cmd: &Commands) -> bool {
22892309
| Commands::GolangciLint { .. }
22902310
| Commands::Gt { .. }
22912311
| Commands::Gcc { .. }
2312+
| Commands::Gxx { .. }
2313+
| Commands::Clang { .. }
2314+
| Commands::Clangxx { .. }
22922315
)
22932316
}
22942317

0 commit comments

Comments
 (0)