mirror of
https://github.com/uutils/coreutils
synced 2024-12-15 07:42:48 +00:00
fmt: implement default for FmtOptions
This commit is contained in:
parent
8940018833
commit
42d6604e59
1 changed files with 25 additions and 17 deletions
|
@ -60,6 +60,29 @@ pub struct FmtOptions {
|
||||||
goal: usize,
|
goal: usize,
|
||||||
tabwidth: 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.
|
/// Parse the command line arguments and return the list of files and formatting options.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
@ -70,6 +93,7 @@ pub struct FmtOptions {
|
||||||
///
|
///
|
||||||
/// A tuple containing a vector of file names and a `FmtOptions` struct.
|
/// A tuple containing a vector of file names and a `FmtOptions` struct.
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
|
#[allow(clippy::field_reassign_with_default)]
|
||||||
fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)> {
|
fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)> {
|
||||||
let matches = uu_app().try_get_matches_from(args)?;
|
let matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
||||||
|
@ -78,23 +102,7 @@ fn parse_arguments(args: impl uucore::Args) -> UResult<(Vec<String>, FmtOptions)
|
||||||
.map(|v| v.map(ToString::to_string).collect())
|
.map(|v| v.map(ToString::to_string).collect())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut fmt_opts = FmtOptions {
|
let mut fmt_opts = FmtOptions::default();
|
||||||
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,
|
|
||||||
};
|
|
||||||
|
|
||||||
fmt_opts.tagged = matches.get_flag(OPT_TAGGED_PARAGRAPH);
|
fmt_opts.tagged = matches.get_flag(OPT_TAGGED_PARAGRAPH);
|
||||||
if matches.get_flag(OPT_CROWN_MARGIN) {
|
if matches.get_flag(OPT_CROWN_MARGIN) {
|
||||||
|
|
Loading…
Reference in a new issue