aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2024-03-18 13:49:18 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2024-03-22 08:07:03 +0000
commit98a9731683696b615b5a94a483aa73a9b418791d (patch)
tree438ed361365dfbfd56cc8a169215e81979f2525d
parent8f13a2c52504a504686ed20c70869f254491ce98 (diff)
downloadsrc-98a9731683696b615b5a94a483aa73a9b418791d.tar.gz
src-98a9731683696b615b5a94a483aa73a9b418791d.zip
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)
-rw-r--r--sbin/bectl/bectl.89
-rw-r--r--sbin/bectl/bectl.c45
2 files changed, 27 insertions, 27 deletions
diff --git a/sbin/bectl/bectl.8 b/sbin/bectl/bectl.8
index 19cd867df56b..b511d5a637b6 100644
--- a/sbin/bectl/bectl.8
+++ b/sbin/bectl/bectl.8
@@ -15,7 +15,7 @@
.\"
.\" @(#)be.1
.\"
-.Dd October 5, 2023
+.Dd March 18, 2024
.Dt BECTL 8
.Os
.Sh NAME
@@ -23,7 +23,7 @@
.Nd Utility to manage boot environments on ZFS
.Sh SYNOPSIS
.Nm
-.Op Fl h\&?
+.Op Fl h
.Nm
.Op Fl r Ar beroot
.Cm activate
@@ -117,10 +117,9 @@ flag to work.
.Ss Supported Subcommands and Flags
.Bl -tag -width activate
.It Xo
-.Fl h |
-.Fl \&?
+.Fl h
.Xc
-Print usage information.
+Print usage information and exit.
.It Xo
.Cm activate
.Op Fl t | Fl T
diff --git a/sbin/bectl/bectl.c b/sbin/bectl/bectl.c
index 05ed8d6be5bd..7632540aa7ad 100644
--- a/sbin/bectl/bectl.c
+++ b/sbin/bectl/bectl.c
@@ -65,7 +65,7 @@ usage(bool explicit)
fp = explicit ? stdout : stderr;
fprintf(fp, "%s",
- "Usage:\tbectl {-h | -? | subcommand [args...]}\n"
+ "Usage:\tbectl {-h | subcommand [args...]}\n"
#if SOON
"\tbectl [-r beroot] add (path)*\n"
#endif
@@ -546,27 +546,31 @@ main(int argc, char *argv[])
{
struct command_map_entry *cmd;
const char *command;
- char *root;
- int rc;
+ char *root = NULL;
+ int opt, rc;
- cmd = NULL;
- root = NULL;
- if (argc < 2)
- return (usage(false));
-
- if (strcmp(argv[1], "-r") == 0) {
- if (argc < 4)
- return (usage(false));
- root = strdup(argv[2]);
- command = argv[3];
- argc -= 3;
- argv += 3;
- } else {
- command = argv[1];
- argc -= 1;
- argv += 1;
+ while ((opt = getopt(argc, argv, "hr:")) != -1) {
+ switch (opt) {
+ case 'h':
+ exit(usage(true));
+ case 'r':
+ root = strdup(optarg);
+ break;
+ default:
+ exit(usage(false));
+ }
}
+ argc -= optind;
+ argv += optind;
+
+ if (argc == 0)
+ exit(usage(false));
+
+ command = *argv;
+ optreset = 1;
+ optind = 1;
+
/* Handle command aliases */
if (strcmp(command, "umount") == 0)
command = "unmount";
@@ -574,9 +578,6 @@ main(int argc, char *argv[])
if (strcmp(command, "ujail") == 0)
command = "unjail";
- if ((strcmp(command, "-?") == 0) || (strcmp(command, "-h") == 0))
- return (usage(true));
-
if ((cmd = get_cmd_info(command)) == NULL) {
fprintf(stderr, "Unknown command: %s\n", command);
return (usage(false));