mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
df: add thiserror (#7545)
* refactor: Add thiserror to df * fix: Try fixing tests * refactor(df): Move `df` to `thiserror` * chore(df): Add back comment * chore: Refactor column.rs correctly
This commit is contained in:
parent
dd5517c1ff
commit
3a0b43bdf7
4 changed files with 9 additions and 13 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2672,6 +2672,7 @@ version = "0.0.30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
"thiserror 2.0.12",
|
||||||
"unicode-width 0.2.0",
|
"unicode-width 0.2.0",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
|
@ -20,6 +20,7 @@ path = "src/df.rs"
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
uucore = { workspace = true, features = ["libc", "fsext"] }
|
uucore = { workspace = true, features = ["libc", "fsext"] }
|
||||||
unicode-width = { workspace = true }
|
unicode-width = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
// spell-checker:ignore itotal iused iavail ipcent pcent squashfs
|
// spell-checker:ignore itotal iused iavail ipcent pcent squashfs
|
||||||
use crate::{OPT_INODES, OPT_OUTPUT, OPT_PRINT_TYPE};
|
use crate::{OPT_INODES, OPT_OUTPUT, OPT_PRINT_TYPE};
|
||||||
use clap::{ArgMatches, parser::ValueSource};
|
use clap::{ArgMatches, parser::ValueSource};
|
||||||
|
use thiserror::Error;
|
||||||
|
use uucore::display::Quotable;
|
||||||
|
|
||||||
/// The columns in the output table produced by `df`.
|
/// The columns in the output table produced by `df`.
|
||||||
///
|
///
|
||||||
|
@ -56,9 +58,10 @@ pub(crate) enum Column {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error while defining which columns to display in the output table.
|
/// An error while defining which columns to display in the output table.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
pub(crate) enum ColumnError {
|
pub(crate) enum ColumnError {
|
||||||
/// If a column appears more than once in the `--output` argument.
|
/// If a column appears more than once in the `--output` argument.
|
||||||
|
#[error("{}", .0.quote())]
|
||||||
MultipleColumns(String),
|
MultipleColumns(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ 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::error::Error;
|
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::blocks::{BlockSize, read_block_size};
|
use crate::blocks::{BlockSize, read_block_size};
|
||||||
use crate::columns::{Column, ColumnError};
|
use crate::columns::{Column, ColumnError};
|
||||||
|
@ -426,28 +426,19 @@ where
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
enum DfError {
|
enum DfError {
|
||||||
/// A problem while parsing command-line options.
|
/// A problem while parsing command-line options.
|
||||||
|
#[error("{}", .0)]
|
||||||
OptionsError(OptionsError),
|
OptionsError(OptionsError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for DfError {}
|
|
||||||
|
|
||||||
impl UError for DfError {
|
impl UError for DfError {
|
||||||
fn usage(&self) -> bool {
|
fn usage(&self) -> bool {
|
||||||
matches!(self, Self::OptionsError(OptionsError::ColumnError(_)))
|
matches!(self, Self::OptionsError(OptionsError::ColumnError(_)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for DfError {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::OptionsError(e) => e.fmt(f),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[uucore::main]
|
#[uucore::main]
|
||||||
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let matches = uu_app().try_get_matches_from(args)?;
|
let matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue