Skip to content

Commit 09db8d8

Browse files
committed
fmt: adapt defaults to the ones used by GNU fmt
1 parent 42d6604 commit 09db8d8

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

src/uu/fmt/src/fmt.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl Default for FmtOptions {
7676
use_anti_prefix: false,
7777
anti_prefix: String::new(),
7878
xanti_prefix: false,
79-
width: 79,
80-
goal: 74,
79+
width: 75,
80+
goal: 70,
8181
tabwidth: 8,
8282
}
8383
}
@@ -95,6 +95,9 @@ impl Default for FmtOptions {
9595
#[allow(clippy::cognitive_complexity)]
9696
#[allow(clippy::field_reassign_with_default)]
9797
fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)> {
98+
// by default, goal is 93% of width
99+
const DEFAULT_GOAL_TO_WIDTH_RATIO: usize = 93;
100+
98101
let matches = uu_app().try_get_matches_from(args)?;
99102

100103
let mut files: Vec<String> = matches
@@ -149,7 +152,10 @@ fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)
149152
),
150153
));
151154
}
152-
fmt_opts.goal = cmp::min(fmt_opts.width * 94 / 100, fmt_opts.width - 3);
155+
fmt_opts.goal = cmp::min(
156+
fmt_opts.width * DEFAULT_GOAL_TO_WIDTH_RATIO / 100,
157+
fmt_opts.width - 3,
158+
);
153159
};
154160

155161
if let Some(s) = matches.get_one::<String>(OPT_GOAL) {
@@ -163,7 +169,10 @@ fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)
163169
}
164170
};
165171
if !matches.get_flag(OPT_WIDTH) {
166-
fmt_opts.width = cmp::max(fmt_opts.goal * 100 / 94, fmt_opts.goal + 3);
172+
fmt_opts.width = cmp::max(
173+
fmt_opts.goal * 100 / DEFAULT_GOAL_TO_WIDTH_RATIO,
174+
fmt_opts.goal + 3,
175+
);
167176
} else if fmt_opts.goal > fmt_opts.width {
168177
return Err(USimpleError::new(1, "GOAL cannot be greater than WIDTH."));
169178
}
@@ -364,14 +373,14 @@ pub fn uu_app() -> Command {
364373
Arg::new(OPT_WIDTH)
365374
.short('w')
366375
.long("width")
367-
.help("Fill output lines up to a maximum of WIDTH columns, default 79.")
376+
.help("Fill output lines up to a maximum of WIDTH columns, default 75.")
368377
.value_name("WIDTH"),
369378
)
370379
.arg(
371380
Arg::new(OPT_GOAL)
372381
.short('g')
373382
.long("goal")
374-
.help("Goal width, default ~0.94*WIDTH. Must be less than WIDTH.")
383+
.help("Goal width, default of 93% of WIDTH. Must be less than WIDTH.")
375384
.value_name("GOAL"),
376385
)
377386
.arg(

0 commit comments

Comments
 (0)