Bug 272260 - bectl(8) usage: -?
Summary: bectl(8) usage: -?
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Dag-Erling Smørgrav
URL: https://reviews.freebsd.org/D44405
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-28 02:37 UTC by Graham Perrin
Modified: 2024-03-22 09:17 UTC (History)
4 users (show)

See Also:
des: mfc-stable14+
des: mfc-stable13+


Attachments
format -h|-? properly (506 bytes, patch)
2023-06-28 07:52 UTC, Yuri Pankov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Perrin freebsd_committer freebsd_triage 2023-06-28 02:37:09 UTC
From printed usage information, added at <https://github.com/freebsd/freebsd-src/pull/728/commits/f6f931d28b2d7c231317e52df641f15ef49042f3#diff-c02d05827bafa5f8205b59bd5e53274a6043030b432b47ffcb9bb7907bb5d5f5R124-R127>: 

> Usage:  bectl {-h | -? | subcommand [args...]}

From an earlier edition of the manual page: 

> SYNOPSIS
>      bectl [-h?]

Originally, was what's below the intention? 

    -? to be synonymous with (an alternative to) -h

Actual results: 


% bectl -?
bectl: No match.
% bectl ?
Unknown command: R
Usage:  bectl {-h | -? | subcommand [args...]}
        bectl [-r beroot] activate [-t] beName
        bectl [-r beroot] activate [-T]
        bectl [-r beroot] check
        bectl [-r beroot] create [-r] [-e {nonActiveBe | beName@snapshot}] beName
        bectl [-r beroot] create [-r] beName@snapshot
        bectl [-r beroot] destroy [-Fo] {beName | beName@snapshot}
        bectl [-r beroot] export sourceBe
        bectl [-r beroot] import targetBe
        bectl [-r beroot] jail [-bU] [{-o key=value | -u key}]... beName
              [utility [argument ...]]
        bectl [-r beroot] list [-aDHs] [{-c property | -C property}]
        bectl [-r beroot] mount beName [mountpoint]
        bectl [-r beroot] rename origBeName newBeName
        bectl [-r beroot] {ujail | unjail} {jailID | jailName | beName}
        bectl [-r beroot] {umount | unmount} [-f] beName
% uname -aKU
FreeBSD mowa219-gjp4-8570p-freebsd 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n263799-f81be7a8318b-dirty: Mon Jun 26 22:09:58 BST 2023     grahamperrin@mowa219-gjp4-8570p-freebsd:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64 1400092 1400090
%
Comment 1 Kyle Evans freebsd_committer freebsd_triage 2023-06-28 02:45:36 UTC
> bectl: No match.

That message is going to be coming from your shell somewhere, not bectl.

```
root@aarch64-dev:/usr/src/sbin/bectl# bectl -?
zsh: no matches found: -?
root@aarch64-dev:/usr/src/sbin/bectl# bectl -\?
Usage:  bectl {-h | -? | subcommand [args...]}
        bectl [-r beroot] activate [-t] beName
        bectl [-r beroot] activate [-T]
        bectl [-r beroot] check
        bectl [-r beroot] create [-r] [-e {nonActiveBe | beName@snapshot}] beName
        bectl [-r beroot] create [-r] beName@snapshot
        bectl [-r beroot] destroy [-Fo] {beName | beName@snapshot}
        bectl [-r beroot] export sourceBe
        bectl [-r beroot] import targetBe
        bectl [-r beroot] jail [-bU] [{-o key=value | -u key}]... beName
              [utility [argument ...]]
        bectl [-r beroot] list [-aDHs] [{-c property | -C property}]
        bectl [-r beroot] mount beName [mountpoint]
        bectl [-r beroot] rename origBeName newBeName
        bectl [-r beroot] {ujail | unjail} {jailID | jailName | beName}
        bectl [-r beroot] {umount | unmount} [-f] beName
```

I don't know if I really agree with supporting -? as a synonym for -h, but that's the way it's been since I imported it and I don't see any reason to remove it.
Comment 2 Kyle Evans freebsd_committer freebsd_triage 2023-06-28 02:47:34 UTC
(In reply to Kyle Evans from comment #1)

I suspect you are using csh, because while "match" doesn't appear anywhere outside of comments in bectl / libbe, there is a literal match in csh:

https://cgit.freebsd.org/src/tree/contrib/tcsh/sh.err.c#n262
Comment 3 Graham Perrin freebsd_committer freebsd_triage 2023-06-28 03:07:35 UTC
Thanks, 

(In reply to Kyle Evans from comment #2)

> I suspect you are using csh, …

True. 

I temporarily used sh, then -? became usable.

Is it commonplace for utilities to allow -? as an alternative to -h?
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2023-06-28 03:08:15 UTC
Incidentally, 

> SYNOPSIS
>     bectl [-h?] 

– should that have a vertical line? So: 

> SYNOPSIS
>     bectl [-h | ?] 

(Now I remember, <https://github.com/freebsd/freebsd-src/pull/728/commits/f6f931d28b2d7c231317e52df641f15ef49042f3#diff-c02d05827bafa5f8205b59bd5e53274a6043030b432b47ffcb9bb7907bb5d5f5R26-R28> I could not figure out the markup to achieve it.)
Comment 5 Graham Perrin freebsd_committer freebsd_triage 2023-06-28 03:19:08 UTC
(In reply to Graham Perrin from comment #4)

(Anyone can answer the | / markup questions …)
Comment 6 Tatsuki Makino 2023-06-28 03:35:51 UTC
In any shell, using -? options requires more typing by escaping or quoting like -\?, '-?' or "-?".
Comment 7 Kyle Evans freebsd_committer freebsd_triage 2023-06-28 04:09:12 UTC
(In reply to Graham Perrin from comment #4)

They're synonyms but they are in-fact mutually exclusive, so they would need a vertical bar. You'll get confusing output if you try to do `bectl -\?h` because we don't use getopt(3) here; it's just a couple of hand-rolled strcmp() since there's only all of three options (-h, -?, -r) and two of them are synonyms anyways.
Comment 8 Tatsuki Makino 2023-06-28 04:53:39 UTC
(In reply to Kyle Evans from comment #7)

> because we don't use getopt(3) here;

I've thought it would be better to document whether getopt or getopt_long are used.
On rare occasions I want to know if -- can indicate the end of an option flag.
Although it is a very, very rare case :)
Comment 9 Yuri Pankov freebsd_committer freebsd_triage 2023-06-28 07:52:06 UTC
Created attachment 243051 [details]
format -h|-? properly

Format -h|-? properly; also get rid of Xo where it's not really needed, fixing mandoc lint.
Comment 10 Graham Perrin freebsd_committer freebsd_triage 2023-06-28 18:31:32 UTC
Comment on attachment 243051 [details]
format -h|-? properly

I think, there should be a space either side of the vertical line. 

(Elsewhere in the page, comparable uses of a vertical line do have spaces.)
Comment 11 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2024-03-18 11:55:09 UTC
Because `getopt(3)` returns `?` when it encounters an error, and the usual way to handle said error is to print a usage message and exit, `-?` can usually be relied upon to produce a usage message even if the author of the utility did not think to provide a `-h` option for that purpose.  Some people have improperly internalized this as “`-?` is the standard way to request a usage message”, which is not the case.  The author of `bectl(8)` appears to be one of those people, and hardcoded a check for `-?` in `bectl(8)`'s non-standard command line parser.  My recommendation is to rewrite `bectl(8)` to use `getopt(3)` and remove all mention of `-?` from the usage string and manual page.
Comment 12 commit-hook freebsd_committer freebsd_triage 2024-03-18 13:59:53 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e819534f15308c92afd19166254604995766ce32

commit e819534f15308c92afd19166254604995766ce32
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2024-03-18 13:49:18 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2024-03-18 13:49:18 +0000

    bectl: Use geopt() and drop mention of -?.

    MFC after:      3 days
    PR:             272260
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D44405

 sbin/bectl/bectl.8 |  9 ++++-----
 sbin/bectl/bectl.c | 45 +++++++++++++++++++++++----------------------
 2 files changed, 27 insertions(+), 27 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2024-03-22 09:14:44 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=98a9731683696b615b5a94a483aa73a9b418791d

commit 98a9731683696b615b5a94a483aa73a9b418791d
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2024-03-18 13:49:18 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2024-03-22 08:07:03 +0000

    bectl: Use geopt() and drop mention of -?.

    MFC after:      3 days
    PR:             272260
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D44405

    (cherry picked from commit e819534f15308c92afd19166254604995766ce32)

 sbin/bectl/bectl.8 |  9 ++++-----
 sbin/bectl/bectl.c | 45 +++++++++++++++++++++++----------------------
 2 files changed, 27 insertions(+), 27 deletions(-)
Comment 14 commit-hook freebsd_committer freebsd_triage 2024-03-22 09:15:46 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=95d66df41b832724a6a5e58f4a07cc89639cb660

commit 95d66df41b832724a6a5e58f4a07cc89639cb660
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2024-03-18 13:49:18 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2024-03-22 08:07:34 +0000

    bectl: Use geopt() and drop mention of -?.

    MFC after:      3 days
    PR:             272260
    Reviewed by:    kevans
    Differential Revision:  https://reviews.freebsd.org/D44405

    (cherry picked from commit e819534f15308c92afd19166254604995766ce32)

 sbin/bectl/bectl.8 | 11 ++++-------
 sbin/bectl/bectl.c | 45 +++++++++++++++++++++++----------------------
 2 files changed, 27 insertions(+), 29 deletions(-)