Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/uu/df/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ path = "src/df.rs"
clap = { workspace = true }
uucore = { workspace = true, features = ["libc", "fsext"] }
unicode-width = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
tempfile = { workspace = true }
Expand Down
8 changes: 5 additions & 3 deletions src/uu/df/src/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// file that was distributed with this source code.
// spell-checker:ignore itotal iused iavail ipcent pcent squashfs
use crate::{OPT_INODES, OPT_OUTPUT, OPT_PRINT_TYPE};
use clap::{ArgMatches, parser::ValueSource};
use clap::{parser::ValueSource, ArgMatches};
use thiserror::Error;
use uucore::display::Quotable;

/// The columns in the output table produced by `df`.
///
Expand Down Expand Up @@ -56,9 +58,9 @@ pub(crate) enum Column {
}

/// An error while defining which columns to display in the output table.
#[derive(Debug)]
#[derive(Debug, Error)]
pub(crate) enum ColumnError {
/// If a column appears more than once in the `--output` argument.
#[error("{}", .0.quote())]
MultipleColumns(String),
}

Expand Down
15 changes: 3 additions & 12 deletions src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use uucore::{format_usage, help_about, help_section, help_usage, show};

use clap::{Arg, ArgAction, ArgMatches, Command, parser::ValueSource};

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

use crate::blocks::{BlockSize, read_block_size};
use crate::columns::{Column, ColumnError};
Expand Down Expand Up @@ -426,28 +426,19 @@ where
Ok(result)
}

#[derive(Debug)]
#[derive(Debug, Error)]
enum DfError {
/// A problem while parsing command-line options.
#[error("{}", .0)]
OptionsError(OptionsError),
}

impl Error for DfError {}

impl UError for DfError {
fn usage(&self) -> bool {
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]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().try_get_matches_from(args)?;
Expand Down
Loading