From nobody Fri Mar 22 09:14:10 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4V1Gq64DkVz5G94S; Fri, 22 Mar 2024 09:14:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V1Gq63mGcz4XBG; Fri, 22 Mar 2024 09:14:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711098850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9P/EtchLKWkuCQq8N7xpC6PHZX2gCPAWXMQwFt7qnMI=; b=tgVVDw8YfyoTtRoHdKYxaf5KZZ8PzwvxHkkb/gGATwXE9eYVyiQU6GPp9TLnwO+/NVwjN6 eYnxE9ijmqy3EWIf7OLOok/2V+rWb+Ghjg0bfMWzJ5P81CKjqUPsHDnfz7pe9SKclRUJE4 VyG+BrQBcbqqno4qHWOvPC1yDHsfvOOtKgwP413OnlBK26f81LJ/HoO28AHYac960ZZTWb 5PFgS/jmh6NW3xs7GiO+eq0tjxQdeySIvlhSTlg/ZB1Zo5L5BrTUf1BugeapxOuwLnH5A7 pCYECTzhmYqCGnNhoLLngNMk+GxEIsS5QX1aJdpcLrmCAWa9jdHquhLsNFlfuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711098850; a=rsa-sha256; cv=none; b=vZA04e2i+0WaV8QX7Rdvc9ZQbY5n9+f40L3d2yBvpyHYVX++JjwBMnZteOc8MGzweuF8+x oQI7hHCcl3c68xMUWEdHh7lzh0a0/XfW/lDiuxo+C5shm5CH2ftS/uReB9HNsHxVIJIgKx 6qUnB3hyFp5Yh2mZi86w1AB4xy8/0MGeFd9+2N1RydwLByILtEubSyWEDJBArT1CvLU+bq uERARQjLrKTQwMtLVnEQ6vbSquD5ULi57jqxym7ISIvoiDqwXy0zF6FZEtsGyf919iHyd5 T6bxGQM2Aa5+IznckvKosjl1330LftkQQeLJn4OgaKjHAQGMLz1i1HE+Y/Y/gQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711098850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9P/EtchLKWkuCQq8N7xpC6PHZX2gCPAWXMQwFt7qnMI=; b=joQBem9zZUIDLLkWwM81srKPikCkKcPt4bFOwb/GUAj9nXrDapaL1JS/WI/qSgmmYNRBiw zSjFEcl8nH0cuzR6/+lGKp6aqvhddhXkbcUDUD70bi7fdTUr7weAf3Tct87jJ4P0wtwNty YQp33/35n2Ul6B9qSSWv47Gy0xndQxEXGA8/a/Z+X8/mBGzuCF92mntSr3H08CqEIB3UpP DOUqEIo6u2hsWEAEr9/FGzcuUSfrfvhTv9XI6fbz94kiJZYmCiw9V6G2UKdS3wchBJxe6Y ++urPndNe5jFZN3bZJn6LaAaBK9zKNch4N1U8tRDIV6IA7b8aKEK+6cas0Hezw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4V1Gq63MR1z1CY9; Fri, 22 Mar 2024 09:14:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42M9EA3o061400; Fri, 22 Mar 2024 09:14:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42M9EA4m061397; Fri, 22 Mar 2024 09:14:10 GMT (envelope-from git) Date: Fri, 22 Mar 2024 09:14:10 GMT Message-Id: <202403220914.42M9EA4m061397@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 98a973168369 - stable/14 - bectl: Use geopt() and drop mention of -?. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 98a9731683696b615b5a94a483aa73a9b418791d Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=98a9731683696b615b5a94a483aa73a9b418791d commit 98a9731683696b615b5a94a483aa73a9b418791d Author: Dag-Erling Smørgrav AuthorDate: 2024-03-18 13:49:18 +0000 Commit: Dag-Erling Smørgrav 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(-) 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));