Skip to content

Commit

Permalink
fmt: implement default for FmtOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Apr 18, 2023
1 parent e734be6 commit 7644a75
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/uu/fmt/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ pub struct FmtOptions {
goal: usize,
tabwidth: usize,
}

impl Default for FmtOptions {
fn default() -> Self {
Self {
crown: false,
tagged: false,
mail: false,
uniform: false,
quick: false,
split_only: false,
use_prefix: false,
prefix: String::new(),
xprefix: false,
use_anti_prefix: false,
anti_prefix: String::new(),
xanti_prefix: false,
width: 79,
goal: 74,
tabwidth: 8,
}
}
}

/// Parse the command line arguments and return the list of files and formatting options.
///
/// # Arguments
Expand All @@ -69,6 +92,7 @@ pub struct FmtOptions {
/// # Returns
///
/// A tuple containing a vector of file names and a `FmtOptions` struct.
#[allow(clippy::field_reassign_with_default)]
fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)> {
let matches = uu_app().try_get_matches_from(args)?;

Expand All @@ -77,23 +101,7 @@ fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();

let mut fmt_opts = FmtOptions {
crown: false,
tagged: false,
mail: false,
uniform: false,
quick: false,
split_only: false,
use_prefix: false,
prefix: String::new(),
xprefix: false,
use_anti_prefix: false,
anti_prefix: String::new(),
xanti_prefix: false,
width: 79,
goal: 74,
tabwidth: 8,
};
let mut fmt_opts = FmtOptions::default();

fmt_opts.tagged = matches.get_flag(OPT_TAGGED_PARAGRAPH);
if matches.get_flag(OPT_CROWN_MARGIN) {
Expand Down

0 comments on commit 7644a75

Please sign in to comment.