Skip to content

Commit ea21b10

Browse files
authored
df: support -m with --output (#14742)
1 parent dae88fb commit ea21b10

5 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/uu/df/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ df-help-human-readable = print sizes in human readable format (e.g., 1K 234M 2G)
1818
df-help-si = likewise, but use powers of 1000 not 1024
1919
df-help-inodes = list inode information instead of block usage
2020
df-help-kilo = like --block-size=1K
21+
df-help-mega = like --block-size=1M
2122
df-help-local = limit listing to local file systems
2223
df-help-no-sync = do not invoke sync before getting usage info (default)
2324
df-help-output = use output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted.

src/uu/df/locales/fr-FR.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ df-help-human-readable = afficher les tailles dans un format lisible par l'homme
1818
df-help-si = pareillement, mais utiliser les puissances de 1000 pas 1024
1919
df-help-inodes = lister les informations d'inode au lieu de l'utilisation des blocs
2020
df-help-kilo = comme --block-size=1K
21+
df-help-mega = comme --block-size=1M
2122
df-help-local = limiter l'affichage aux systèmes de fichiers locaux
2223
df-help-no-sync = ne pas invoquer sync avant d'obtenir les informations d'utilisation (par défaut)
2324
df-help-output = utiliser le format de sortie défini par LISTE_CHAMPS, ou afficher tous les champs si LISTE_CHAMPS est omise.

src/uu/df/src/blocks.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// file that was distributed with this source code.
55

66
//! Types for representing and displaying block sizes.
7-
use crate::{OPT_BLOCKSIZE, OPT_PORTABILITY};
7+
use crate::{OPT_BLOCKSIZE, OPT_KILO, OPT_MEGA, OPT_PORTABILITY};
88
use clap::ArgMatches;
99
use std::fmt;
1010

@@ -171,6 +171,10 @@ pub(crate) fn read_block_size(matches: &ArgMatches) -> Result<BlockSize, ParseSi
171171
} else {
172172
Err(ParseSizeError::ParseFailure(format!("{}", s.quote())))
173173
}
174+
} else if matches.get_flag(OPT_KILO) {
175+
Ok(BlockSize::Bytes(1024))
176+
} else if matches.get_flag(OPT_MEGA) {
177+
Ok(BlockSize::Bytes(1024 * 1024))
174178
} else if matches.get_flag(OPT_PORTABILITY) {
175179
Ok(BlockSize::default())
176180
} else if let Some(bytes) =

src/uu/df/src/df.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static OPT_HUMAN_READABLE_BINARY: &str = "human-readable-binary";
4848
static OPT_HUMAN_READABLE_DECIMAL: &str = "human-readable-decimal";
4949
static OPT_INODES: &str = "inodes";
5050
static OPT_KILO: &str = "kilo";
51+
static OPT_MEGA: &str = "mega";
5152
static OPT_LOCAL: &str = "local";
5253
static OPT_NO_SYNC: &str = "no-sync";
5354
static OPT_OUTPUT: &str = "output";
@@ -562,7 +563,7 @@ pub fn uu_app() -> Command {
562563
.short('B')
563564
.long(OPT_BLOCKSIZE_LONG)
564565
.value_name("SIZE")
565-
.overrides_with_all([OPT_KILO, OPT_BLOCKSIZE])
566+
.overrides_with_all([OPT_KILO, OPT_MEGA, OPT_BLOCKSIZE])
566567
.help(translate!("df-help-block-size")),
567568
)
568569
.arg(
@@ -600,7 +601,14 @@ pub fn uu_app() -> Command {
600601
Arg::new(OPT_KILO)
601602
.short('k')
602603
.help(translate!("df-help-kilo"))
603-
.overrides_with_all([OPT_BLOCKSIZE, OPT_KILO])
604+
.overrides_with_all([OPT_BLOCKSIZE, OPT_KILO, OPT_MEGA])
605+
.action(ArgAction::SetTrue),
606+
)
607+
.arg(
608+
Arg::new(OPT_MEGA)
609+
.short('m')
610+
.help(translate!("df-help-mega"))
611+
.overrides_with_all([OPT_BLOCKSIZE, OPT_KILO, OPT_MEGA])
604612
.action(ArgAction::SetTrue),
605613
)
606614
.arg(

tests/by-util/test_df.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,16 @@ fn test_block_size_1024() {
640640
assert_eq!(get_header(1_000_000_000_000), "1TB-blocks");
641641
}
642642

643+
#[test]
644+
fn test_block_size_1m_option_with_output() {
645+
for args in [["-m", "--output=size"], ["--output=size", "-m"]] {
646+
let output = new_ucmd!().args(&args).succeeds().stdout_str_lossy();
647+
let header = output.lines().next().unwrap().trim();
648+
649+
assert_eq!(header, "1M-blocks");
650+
}
651+
}
652+
643653
#[test]
644654
fn test_block_size_with_suffix() {
645655
fn get_header(block_size: &str) -> String {

0 commit comments

Comments
 (0)