Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 15 additions & 36 deletions src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use uucore::{format_usage, help_about, help_section, help_usage, show};
use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource};

use std::ffi::OsString;
use std::fmt;
use std::path::Path;
use thiserror::Error;

Expand Down Expand Up @@ -114,52 +113,32 @@ impl Default for Options {
}
}

#[derive(Debug)]
#[derive(Debug, Error)]
enum OptionsError {
// TODO This needs to vary based on whether `--block-size`
// or `-B` were provided.
#[error("--block-size argument '{0}' too large")]
BlockSizeTooLarge(String),
// TODO This needs to vary based on whether `--block-size`
// or `-B` were provided.,
#[error("invalid --block-size argument {0}")]
InvalidBlockSize(String),
// TODO This needs to vary based on whether `--block-size`
// or `-B` were provided.
#[error("invalid suffix in --block-size argument {0}")]
InvalidSuffix(String),

/// An error getting the columns to display in the output table.
#[error("option --output: field {0} used more than once")]
ColumnError(ColumnError),

#[error("{}", .0.iter()
.map(|t| format!("file system type {} both selected and excluded", t.quote()))
.collect::<Vec<_>>()
.join(format!("\n{}: ", uucore::util_name()).as_str()))]
FilesystemTypeBothSelectedAndExcluded(Vec<String>),
}

impl fmt::Display for OptionsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
// TODO This needs to vary based on whether `--block-size`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we want to keep the various TODO here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes definitely. I took a look implementing the TODO but it certainly is harder than it seems. I get now why its a TODO. I'll take a look at that separately.

I've put the TODO comments back in. Thanks.

// or `-B` were provided.
Self::BlockSizeTooLarge(s) => {
write!(f, "--block-size argument {} too large", s.quote())
}
// TODO This needs to vary based on whether `--block-size`
// or `-B` were provided.
Self::InvalidBlockSize(s) => write!(f, "invalid --block-size argument {s}"),
// TODO This needs to vary based on whether `--block-size`
// or `-B` were provided.
Self::InvalidSuffix(s) => write!(f, "invalid suffix in --block-size argument {s}"),
Self::ColumnError(ColumnError::MultipleColumns(s)) => write!(
f,
"option --output: field {} used more than once",
s.quote()
),
#[allow(clippy::print_in_format_impl)]
Self::FilesystemTypeBothSelectedAndExcluded(types) => {
for t in types {
eprintln!(
"{}: file system type {} both selected and excluded",
uucore::util_name(),
t.quote()
);
}
Ok(())
}
}
}
}

impl Options {
/// Convert command-line arguments into [`Options`].
fn from(matches: &ArgMatches) -> Result<Self, OptionsError> {
Expand Down
Loading