Skip to content

Commit f7fdfbf

Browse files
committed
Bug fix re formatting of abbreviated flag names
1 parent a2057aa commit f7fdfbf

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/bazel_flags.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@ pub fn combine_key_value_flags(lines: &mut [crate::parser::Line], bazel_flags: &
227227
new_flags.push(
228228
|| -> Option<Spanned<String>> {
229229
let flag_name = &flag.name.as_ref()?.0;
230-
let (_, info) = bazel_flags.get_by_invocation(flag_name)?;
231-
if flag.value.is_some() {
230+
let (lookup_type, info) = bazel_flags.get_by_invocation(flag_name)?;
231+
if flag.value.is_some() || lookup_type == FlagLookupType::Abbreviation {
232+
// If we already have an associated value or if the flag was referred to
233+
// using it's abbreviated name, we don't combine the flag.
234+
// Note that the `-c=opt` would be invalid, only `-c opt` is valid.
232235
return flag.value.clone();
233236
} else if info.requires_value() {
234237
// Combine with the next flag

src/formatting.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ fn test_pretty_print_combined_flags() {
351351
"build --keep_going --foobar\n"
352352
);
353353

354+
// Leaves abbreviated flag names alone. `-cdbg` would not be valid.
355+
assert_eq!(
356+
pretty_print("build -c dbg", &flags, lf).unwrap(),
357+
"build -c dbg\n"
358+
);
359+
354360
// Handles empty parameters correctly
355361
assert_eq!(
356362
pretty_print("build --x \"\"", &flags, lf).unwrap(),

0 commit comments

Comments
 (0)