From nobody Mon Mar 18 13:59:06 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 4TyxKk6jtLz5DnLM; Mon, 18 Mar 2024 13:59:06 +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 4TyxKk65pNz4Mnx; Mon, 18 Mar 2024 13:59:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710770346; 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=g5YlV8gXoOw9gO2tEWiaPUPJZcTiOcV+OiHmQVCY8wk=; b=w93dcixHORjZx7peVCJ2HkZjSqSgC/sUtFSc1zio615+FP8UaG7jmOYE/7th4OqhVUgAz7 yb25iH6I5y/P4edMrsbiKvk5PP0n8vUnzoFDZ3rcu9DV2F9BykwvajIvT6ekS6w9xLICCi 6/OkNtEGz60oKoHKuhbQL1exEPmHbtGiNYuaBMU9eQVUXTd70Yal1NSWZ/oo/oxxMVG6V8 BxDh3ixtt5QIKwep13IQorMIPMC1oZ0Z/C2aVC1N5vteuKsoQsmGe89/2dNE9kXlhCJ4yA JsXgQVmnIvtSTmmByJFT6NCUnFzBNUDz6oTd7Ab26TVhf+KA77OTpq8D8PrWHQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710770346; a=rsa-sha256; cv=none; b=Sf9n5paRbALjtZkLu2i/rNietYNRkmiwn+oy4pFhghNiX6M3lH0xEZkPukc6yVD+KFfXJX m/t4UF8PhRDsKRE9WGEdEsX+xdzp/OhFkqq3K3wN3N4H2qoNxZLs3/SjTP+T1cM04GuelN utQ55uj2MUATRVWPeUuXxToefB1uYn1NLqvTRTk0nr8085Wcbd+ODT72GJhSPxiBqvMcEx TPfDk5v0LwWXkvlOwzW5tyqXD+EnI4lB/qHxbD7m4hh6VrysT1dH9xMpAVoG/EIe+wkXrc c7tlJYXwunic5WXxOWYe2QbBqFYge03XhopB/Vt9nzNlXz1Umi3QyYOyj0haPg== 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=1710770346; 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=g5YlV8gXoOw9gO2tEWiaPUPJZcTiOcV+OiHmQVCY8wk=; b=KYrP5hmKW0zEJlhD75wI/oU28+QnIA6vCWOBHrWoyvZZkTX7Xz83D9XJnYvX109teRDOG2 FbVsHN4eXbzio/MvvNWshkatObqauKVHaOQog9oYSw8mWlwBnsG9Mw1EUu05ERW59FASyK LQ8Wvry15UWmPhaMXA/djWgUBT1uj4c2bCBP6hPsqvB6hQ/JNeYYPPMU5XsfxW9fx0PM23 t9NMWTB37BM5lCQZdI8VEHv87SIgOeH5gc8p61ctu3lZMvwhZ4+9g0jNclSsUSjiMDtAKw t+i8Yj3COfql54q8aXHFUC8+R2kRomuqVqhk7O88UzEQm7YHFfTVLRPAixBqeg== 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 4TyxKk5NqgzQ4B; Mon, 18 Mar 2024 13:59:06 +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 42IDx6WH098231; Mon, 18 Mar 2024 13:59:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42IDx6xM098228; Mon, 18 Mar 2024 13:59:06 GMT (envelope-from git) Date: Mon, 18 Mar 2024 13:59:06 GMT Message-Id: <202403181359.42IDx6xM098228@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: e819534f1530 - main - 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/main X-Git-Reftype: branch X-Git-Commit: e819534f15308c92afd19166254604995766ce32 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e819534f15308c92afd19166254604995766ce32 commit e819534f15308c92afd19166254604995766ce32 Author: Dag-Erling Smørgrav AuthorDate: 2024-03-18 13:49:18 +0000 Commit: Dag-Erling Smørgrav 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(-) diff --git a/sbin/bectl/bectl.8 b/sbin/bectl/bectl.8 index 93244c52ce4d..be927d123e9f 100644 --- a/sbin/bectl/bectl.8 +++ b/sbin/bectl/bectl.8 @@ -13,7 +13,7 @@ .\" documentation and/or other materials provided with the distribution. .\" .\" -.Dd October 5, 2023 +.Dd March 18, 2024 .Dt BECTL 8 .Os .Sh NAME @@ -21,7 +21,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 @@ -115,10 +115,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 e398e055a3b2..68f3de5b7e78 100644 --- a/sbin/bectl/bectl.c +++ b/sbin/bectl/bectl.c @@ -64,7 +64,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 @@ -545,27 +545,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"; @@ -573,9 +577,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));