mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
Merge pull request #7673 from lewisboon/df-thiserror
df: migrate OptionsError to thiserror
This commit is contained in:
commit
bf9a8b83f8
1 changed files with 15 additions and 36 deletions
|
@ -20,7 +20,6 @@ use uucore::{format_usage, help_about, help_section, help_usage, show};
|
||||||
use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource};
|
use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource};
|
||||||
|
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fmt;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
@ -114,52 +113,32 @@ impl Default for Options {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
enum OptionsError {
|
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),
|
BlockSizeTooLarge(String),
|
||||||
|
// TODO This needs to vary based on whether `--block-size`
|
||||||
|
// or `-B` were provided.,
|
||||||
|
#[error("invalid --block-size argument {0}")]
|
||||||
InvalidBlockSize(String),
|
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),
|
InvalidSuffix(String),
|
||||||
|
|
||||||
/// An error getting the columns to display in the output table.
|
/// An error getting the columns to display in the output table.
|
||||||
|
#[error("option --output: field {0} used more than once")]
|
||||||
ColumnError(ColumnError),
|
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>),
|
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`
|
|
||||||
// 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 {
|
impl Options {
|
||||||
/// Convert command-line arguments into [`Options`].
|
/// Convert command-line arguments into [`Options`].
|
||||||
fn from(matches: &ArgMatches) -> Result<Self, OptionsError> {
|
fn from(matches: &ArgMatches) -> Result<Self, OptionsError> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue