[git commit] cut: tweak --help

Denys Vlasenko vda.linux at googlemail.com
Wed Dec 11 00:10:05 UTC 2024


commit: https://git.busybox.net/busybox/commit/?id=a4894eaf713f0e452c272db1c5dc2a459e05808f
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
packed_usage                                       34901   34934     +33
cut_main                                            1353    1339     -14
.rodata                                           105724  105685     -39
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 33/-53)            Total: -20 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/cut.c  | 17 ++++++++---------
 libbb/getopt32.c |  4 ++--
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/coreutils/cut.c b/coreutils/cut.c
index 2d0a6237c..1e9867858 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -27,7 +27,8 @@
 //kbuild:lib-$(CONFIG_CUT) += cut.o
 
 //usage:#define cut_trivial_usage
-//usage:       "[OPTIONS] [FILE]..."
+//usage:       "{-b|c LIST | -f"IF_FEATURE_CUT_REGEX("|F")" LIST [-d SEP] [-s]} [-D] [-O SEP] [FILE]..."
+//  --output-delimiter SEP is too long to fit into 80 char-wide help ----------------^^^^^^^^
 //usage:#define cut_full_usage "\n\n"
 //usage:       "Print selected fields from FILEs to stdout\n"
 //usage:     "\n	-b LIST	Output only bytes from LIST"
@@ -44,11 +45,7 @@
 //usage:     "\n	-s	Drop lines with no delimiter (else print them in full)"
 //usage:     "\n	-D	Don't sort/collate sections or match -f"IF_FEATURE_CUT_REGEX("F")" lines without delimeter"
 //usage:     IF_LONG_OPTS(
-//usage:     IF_FEATURE_CUT_REGEX(
-//usage:     "\n	--output-delimiter SEP Output field delimeter (default = -d for -f, one space for -F)"
-//usage:     ) IF_NOT_FEATURE_CUT_REGEX(
-//usage:     "\n	--output-delimiter SEP Output field delimeter (default = -d)"
-//usage:     )
+//usage:     "\n	--output-delimiter SEP	Output field delimeter"
 //usage:     ) IF_NOT_LONG_OPTS(
 //usage:     IF_FEATURE_CUT_REGEX(
 //usage:     "\n	-O SEP	Output field delimeter (default = -d for -f, one space for -F)"
@@ -302,7 +299,8 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
 #else
 	opt = getopt32long(argv, "^"
 			OPT_STR  // = "b:c:f:d:O:sD"IF_FEATURE_CUT_REGEX("F:")"n"
-			"\0" "b--"ARG":c--"ARG":f--"ARG IF_FEATURE_CUT_REGEX("F--"ARG),
+			"\0" "b:c:f:"IF_FEATURE_CUT_REGEX("F:") /* one of -bcfF is required */
+			"b--"ARG":c--"ARG":f--"ARG IF_FEATURE_CUT_REGEX(":F--"ARG), /* they are mutually exclusive */
 			cut_longopts,
 			&sopt, &sopt, &sopt, &delim, &odelim IF_FEATURE_CUT_REGEX(, &sopt)
 	);
@@ -314,8 +312,9 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
 
 //	argc -= optind;
 	argv += optind;
-	if (!(opt & (OPT_BYTE | OPT_CHAR | OPT_FIELDS | OPT_REGEX)))
-		bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
+	//if (!(opt & (OPT_BYTE | OPT_CHAR | OPT_FIELDS | OPT_REGEX)))
+	//	bb_simple_error_msg_and_die("expected a list of bytes, characters, or fields");
+	// ^^^ handled by getopt32
 
 	/*  non-field (char or byte) cutting has some special handling */
 	if (!(opt & (OPT_FIELDS|OPT_REGEX))) {
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index a8dd85159..b5efa19ac 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -93,7 +93,7 @@ getopt32(char **argv, const char *applet_opts, ...)
 
  "!"    If the first character in the applet_opts string is a '!',
         report bad options, missing required options,
-        inconsistent options with all-ones return value (instead of abort.
+        inconsistent options with all-ones return value instead of aborting.
 
  "+"    If the first character in the applet_opts string is a plus,
         then option processing will stop as soon as a non-option is
@@ -265,7 +265,7 @@ Special characters:
         for "long options only" cases, such as tar --exclude=PATTERN,
         wget --header=HDR cases.
 
- "a?b"  A "?" between an option and a group of options means that
+ "a?bc" A "?" between an option and a group of options means that
         at least one of them is required to occur if the first option
         occurs in preceding command line arguments.
 


More information about the busybox-cvs mailing list