summaryrefslogtreecommitdiffhomepage
path: root/src/internal/argv
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2024-05-28 14:55:48 +0000
committermidipix <writeonce@midipix.org>2024-05-28 15:07:41 +0000
commit9f82d547de04b9aa0de20e9b01ca614c50fc1b2f (patch)
treebfe6c747a5cf0bb09068ae7e2efd8424ebfbe553 /src/internal/argv
parent87214883dcc6ae5f0e5458b36b33aa0553aabe87 (diff)
downloadntux-9f82d547de04b9aa0de20e9b01ca614c50fc1b2f.tar.bz2
ntux-9f82d547de04b9aa0de20e9b01ca614c50fc1b2f.tar.xz
argv.h: usage screen: avoid extra <stace> when all long options are hybrid-only.
Diffstat (limited to 'src/internal/argv')
-rw-r--r--src/internal/argv/argv.h12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/internal/argv/argv.h b/src/internal/argv/argv.h
index b66d9ea..c6d8230 100644
--- a/src/internal/argv/argv.h
+++ b/src/internal/argv/argv.h
@@ -833,6 +833,7 @@ static void argv_usage_impl(
{
const struct argv_option ** optv;
const struct argv_option * option;
+ int nlong;
bool fshort,flong,fboth;
size_t len,optlen,desclen;
char cache;
@@ -865,7 +866,7 @@ static void argv_usage_impl(
if (header)
argv_dprintf(fd,"%s",header);
- for (optlen=0,optv=options; *optv; optv++) {
+ for (optlen=0,nlong=0,optv=options; *optv; optv++) {
option = *optv;
/* indent + comma */
@@ -884,6 +885,11 @@ static void argv_usage_impl(
/* optlen */
if (len > optlen)
optlen = len;
+
+ /* long (vs. hybrid-only) option? */
+ if (option->long_name)
+ if (!(option->flags & ARGV_OPTION_HYBRID_ONLY))
+ nlong++;
}
if (optlen >= optcap) {
@@ -918,6 +924,10 @@ static void argv_usage_impl(
prefix = option->flags & ARGV_OPTION_HYBRID_ONLY
? " -" : " --";
+ /* avoid extra <stace> when all long opts are hybrid-only */
+ if (nlong == 0)
+ prefix++;
+
/* option string */
if (fboth && option->short_name && option->long_name)
sprintf(optstr,"%s-%c,%s%s",