mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
df: show "block-size argument too large" error
This commit is contained in:
parent
69f8543d8f
commit
15412f100a
2 changed files with 39 additions and 6 deletions
|
@ -14,6 +14,7 @@ mod table;
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{UError, UResult, USimpleError};
|
use uucore::error::{UError, UResult, USimpleError};
|
||||||
use uucore::fsext::{read_fs_list, MountInfo};
|
use uucore::fsext::{read_fs_list, MountInfo};
|
||||||
|
use uucore::parse_size::ParseSizeError;
|
||||||
use uucore::{format_usage, show};
|
use uucore::{format_usage, show};
|
||||||
|
|
||||||
use clap::{crate_version, Arg, ArgMatches, Command};
|
use clap::{crate_version, Arg, ArgMatches, Command};
|
||||||
|
@ -105,7 +106,8 @@ impl Default for Options {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum OptionsError {
|
enum OptionsError {
|
||||||
InvalidBlockSize,
|
BlockSizeTooLarge(String),
|
||||||
|
InvalidBlockSize(String),
|
||||||
|
|
||||||
/// An error getting the columns to display in the output table.
|
/// An error getting the columns to display in the output table.
|
||||||
ColumnError(ColumnError),
|
ColumnError(ColumnError),
|
||||||
|
@ -116,11 +118,14 @@ enum OptionsError {
|
||||||
impl fmt::Display for OptionsError {
|
impl fmt::Display for OptionsError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
// TODO This should include the raw string provided as the argument.
|
|
||||||
//
|
|
||||||
// TODO This needs to vary based on whether `--block-size`
|
// TODO This needs to vary based on whether `--block-size`
|
||||||
// or `-B` were provided.
|
// or `-B` were provided.
|
||||||
Self::InvalidBlockSize => write!(f, "invalid --block-size argument"),
|
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),
|
||||||
Self::ColumnError(ColumnError::MultipleColumns(s)) => write!(
|
Self::ColumnError(ColumnError::MultipleColumns(s)) => write!(
|
||||||
f,
|
f,
|
||||||
"option --output: field {} used more than once",
|
"option --output: field {} used more than once",
|
||||||
|
@ -155,8 +160,12 @@ impl Options {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
show_local_fs: matches.is_present(OPT_LOCAL),
|
show_local_fs: matches.is_present(OPT_LOCAL),
|
||||||
show_all_fs: matches.is_present(OPT_ALL),
|
show_all_fs: matches.is_present(OPT_ALL),
|
||||||
block_size: block_size_from_matches(matches)
|
block_size: block_size_from_matches(matches).map_err(|e| match e {
|
||||||
.map_err(|_| OptionsError::InvalidBlockSize)?,
|
ParseSizeError::SizeTooBig(_) => OptionsError::BlockSizeTooLarge(
|
||||||
|
matches.value_of(OPT_BLOCKSIZE).unwrap().to_string(),
|
||||||
|
),
|
||||||
|
ParseSizeError::ParseFailure(s) => OptionsError::InvalidBlockSize(s),
|
||||||
|
})?,
|
||||||
include,
|
include,
|
||||||
exclude,
|
exclude,
|
||||||
show_total: matches.is_present(OPT_TOTAL),
|
show_total: matches.is_present(OPT_TOTAL),
|
||||||
|
|
|
@ -419,6 +419,30 @@ fn test_block_size_with_suffix() {
|
||||||
//assert_eq!(get_header("1GB"), "1GB-blocks");
|
//assert_eq!(get_header("1GB"), "1GB-blocks");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_too_large_block_size() {
|
||||||
|
fn run_command(size: &str) {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg(format!("--block-size={}", size))
|
||||||
|
.fails()
|
||||||
|
.stderr_contains(format!("--block-size argument '{}' too large", size));
|
||||||
|
}
|
||||||
|
|
||||||
|
let too_large_sizes = vec!["1Y", "1Z"];
|
||||||
|
|
||||||
|
for size in too_large_sizes {
|
||||||
|
run_command(size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_block_size() {
|
||||||
|
new_ucmd!()
|
||||||
|
.arg("--block-size=x")
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("invalid --block-size argument 'x'");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_output_selects_columns() {
|
fn test_output_selects_columns() {
|
||||||
let output = new_ucmd!()
|
let output = new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue