-/// Parsed command line options.
-#[derive(Clone, Debug, Default)]
-pub struct CliOptions {
- skip_children: Option<bool>,
- quiet: bool,
- verbose: bool,
- pub(super) config_path: Option<PathBuf>,
- write_mode: Option<WriteMode>,
- check: bool,
- color: Option<Color>,
- file_lines: FileLines, // Default is all lines in all files.
- unstable_features: bool,
- error_on_unformatted: Option<bool>,
-}
-
-impl CliOptions {
- pub fn from_matches(matches: &Matches) -> FmtResult<CliOptions> {
- let mut options = CliOptions::default();
- options.verbose = matches.opt_present("verbose");
- options.quiet = matches.opt_present("quiet");
- if options.verbose && options.quiet {
- return Err(format_err!("Can't use both `--verbose` and `--quiet`"));
- }
-
- let unstable_features = matches.opt_present("unstable-features");
- let rust_nightly = option_env!("CFG_RELEASE_CHANNEL")
- .map(|c| c == "nightly")
- .unwrap_or(false);
- if unstable_features && !rust_nightly {
- return Err(format_err!(
- "Unstable features are only available on Nightly channel"
- ));
- } else {
- options.unstable_features = unstable_features;
- }