On 03/02/2014 05:38 PM, Bernhard Voelker wrote:
> On 03/02/2014 03:33 PM, Pádraig Brady wrote:
>> On 03/02/2014 12:33 PM, Mateusz Jończyk wrote:
>>> Hello,
>>> There should be a warning when running df --si -h because it will display 
>>> results
>>> in blocks of 1024 and not 1000, as one might think (the switch --si 
>>> displays blocks
>>> in a human-readable format when used by itself).
>>
>> This is confusing.
> 
> Indeed, or not ...
> 
>> I think the confusion stems from the option names themselves.
>> I.E. I'm not sure you'd want to warn as you might want to support overriding 
>> options.
>> Consider: alias df='df -h'
>>
>> Then you could very well want to `df -H` to override the power from 1024 to 
>> 1000.
> 
> ... because df really honors the last given option (as expected):

Yep that's my point. I.E. we should probably not issue a warning in this case.

>> So really the option should be --human-si not just --si.
> 
> Well, I'm 80:20 against this. Df(1) just honors the latest option
> given - no matter what the name of the option's name is.  Renaming
> an option is almost always a "suboptimal" thing for users.
> In this case, some might be already used to type "df --human" which
> would not be distinguishable from --human-si anymore.

I completely agree. --human-si would be bad for this reason.
--si-human perhaps would be better and backwards compatible,
though probably not worth it because it would introduce incompatibility
for scripts using the full --si-human and older systems supporting just --si.

> The problem is maybe that "df --help" doesn't explicitly say that -h
> is using powers of 1024 no matter what other option was given before.
> 
>   -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 
> 2G)
>   -H, --si              likewise, but use powers of 1000 not 1024
> 
> However, the info page is quite clear about this:

Very few read info pages, and anyway in this case we should be clear at the man 
page level.

Mateusz stated the issue was that on a quick glance, the --si option wasn't 
described
well enough in isolation. Likewise, the description of -h requires reading that 
of -H
to know the power used. So hopefully the attached patch fixes this and more.

thanks,
Pádraig.
>From 13bb95c51ac307cf008595971de4b47baa127dc4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Mon, 3 Mar 2014 02:49:25 +0000
Subject: [PATCH] doc: improve df --human and --si, help and man page

* src/df.c (usage): Adjust the --human and --si descriptions
to not depend on each other.  Also include an example that is
illustrative of the rounding, suffix, width, and localized fractions.
Fixes http://bugs.gnu.org/16922
---
 src/df.c |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/df.c b/src/df.c
index e4fafb9..7143ff2 100644
--- a/src/df.c
+++ b/src/df.c
@@ -1252,6 +1252,18 @@ usage (int status)
     emit_try_help ();
   else
     {
+      const int example_size = 1023*1024*1024;
+
+      int opts = human_autoscale;
+
+      opts |= human_SI;
+      char si_buf[LONGEST_HUMAN_READABLE + 1];
+      char const *si = human_readable (example_size, si_buf, opts, 1, 1);
+
+      opts |= human_base_1024;
+      char human_buf[LONGEST_HUMAN_READABLE + 1];
+      char const *human = human_readable (example_size, human_buf, opts, 1, 1);
+
       printf (_("Usage: %s [OPTION]... [FILE]...\n"), program_name);
       fputs (_("\
 Show information about the file system on which each FILE resides,\n\
@@ -1260,16 +1272,15 @@ or all file systems by default.\n\
 
       emit_mandatory_arg_note ();
 
-      fputs (_("\
+      printf (_("\
   -a, --all             include dummy file systems\n\
   -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,\n\
                            '-BM' prints sizes in units of 1,048,576 bytes;\n\
                            see SIZE format below\n\
       --total           produce a grand total\n\
-  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)\
-\n\
-  -H, --si              likewise, but use powers of 1000 not 1024\n\
-"), stdout);
+  -h, --human-readable  print abbreviated sizes in powers of 1024 (e.g. %s)\n\
+  -H, --si              print abbreviated sizes in powers of 1000 (e.g. %s)\n\
+"), human, si);
       fputs (_("\
   -i, --inodes          list inode information instead of block usage\n\
   -k                    like --block-size=1K\n\
-- 
1.7.7.6

Reply via email to