From patchwork Tue Sep 10 18:32:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Sexton X-Patchwork-Id: 1233 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 318FF13271EC2 for ; Tue, 10 Sep 2019 18:32:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=DKIM_ADSP_CUSTOM_MED=0.001, DKIM_INVALID=1,DKIM_SIGNED=0.1,FREEMAIL_FROM=0.5,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,SPOOFED_FREEMAIL=1.998, T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=no autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Tue, 10 Sep 2019 18:32:14 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 5B0AA154015E4D; Tue, 10 Sep 2019 18:32:12 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Tue, 10 Sep 2019 18:32:12 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 226752BDBA; Tue, 10 Sep 2019 18:32:12 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TX/cZ2ir Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 19B772BDB6 for ; Tue, 10 Sep 2019 18:32:09 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Tue, 10 Sep 2019 18:32:09 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 1CF99154015E4B for ; Tue, 10 Sep 2019 18:32:08 +0000 (UTC) Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Tue, 10 Sep 2019 18:32:08 +0000 (UTC) Received: by mail-qt1-x829.google.com with SMTP id o12so21993823qtf.3 for ; Tue, 10 Sep 2019 11:32:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=e/u4MeLv09Oux8GddXzBHu5H3A8JYozHz58mmmkZGHY=; b=TX/cZ2irP31bQ69CkDAuMelA7aYYO6Ymbt5m82gSEJcqjENE1xf7c0s8/FU0OUQCdc 4/Scb15l+TttQhJ2tmaB6p+BAhYEK6t9IFa6Eojf6wtsHJr2wwmrNkVxoDz0N3noEjnu FgupTESxEc6AC1AyHd0ZmUNwao25WwPDY8nsKwuvMywe4pfdIGveGCOzyg27v213PdzU ho/eNqeXcISaRaWIHjD6bkTfynjTjjPbyeATvhOz5JGLHDzr8aUqictsdJtyV+EqXVI9 KNuUVW5eK7TZFg7CsdYwUCVYrmxnXsSsHrVcTlTKa95MOQduu84dm9+73HgjD1xlXSkn m5+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=e/u4MeLv09Oux8GddXzBHu5H3A8JYozHz58mmmkZGHY=; b=Igx3ELbNmTfNi8+UMdlt2EEwuSYKZIZN1OpxLiIamfnRkii5ZUFQ5beHqELohTyPOd ag86UId5O5nN+eMjWfP0j+Jpbab5f0/rKMobQR7ARv9fcdwzHtDr1Km2e1iCObilV5eY Cek5Z3yRBwBZPPy3gGbq3TGKQh/IZytswBdHlBKgS9gqPMURcxnnxQxusuE+wbnIsty+ KQoOCmmYkYaVJqNvPE0O1Yi/q9Z42TpkhLZh0OK3EbFsX/ryz2K5ReH7RMoyaTVtC/6J ixhcZV5faNIasyQmPyAheojSHWA/mQxVwTGWmh4en7E+uW0E0OA5eM3hH5p9yw9DCpI2 l1SA== X-Gm-Message-State: APjAAAU9YUA13veVsjF0+pyy5hMOkijQBcLg5eDgZwChfM911Ha7+HvI f6fIiAHaQwhysftD9o4ql9oas9YaWLs= X-Google-Smtp-Source: APXvYqzJ1SkHdNY9jf186ILzqo3xhUurrZK6TAYGY2VCyliPBtkwKDOcMczdQZ4NwRFDyHdrndlTXQ== X-Received: by 2002:ac8:6b93:: with SMTP id z19mr31448454qts.48.1568140324981; Tue, 10 Sep 2019 11:32:04 -0700 (PDT) Received: from archangel.localdomain (209.50.154.216.res-cmts.eph2.ptd.net. [209.50.154.216]) by smtp.gmail.com with ESMTPSA id n42sm11360973qta.31.2019.09.10.11.32.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 11:32:04 -0700 (PDT) From: Matthew Sexton To: pacman-dev@archlinux.org Date: Tue, 10 Sep 2019 14:32:03 -0400 Message-Id: <20190910183203.204087-1-wsdmatty@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [pacman-dev] [PATCH] pacman/pacman-conf: -i/--is-set switch, returns 0 if option set X-BeenThere: pacman-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Discussion list for pacman development Errors-To: pacman-dev-bounces@archlinux.org Sender: "pacman-dev" Returns 1 if option not set. Returns 1 with error to stderr if flag does not exist. Case insensitive. Signed-off-by: Matthew Sexton --- src/pacman/pacman-conf.c | 44 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c index efc62cdd..ada4bd9f 100644 --- a/src/pacman/pacman-conf.c +++ b/src/pacman/pacman-conf.c @@ -25,7 +25,7 @@ const char *myname = "pacman-conf", *myver = "1.0.0"; alpm_list_t *directives = NULL; -char sep = '\n', *repo_name = NULL; +char sep = '\n', *repo_name = NULL, *check_name = NULL; const char *config_file = NULL; int repo_list = 0, verbose = 0; @@ -47,6 +47,7 @@ static void usage(int ret) fputs(_(" -r, --repo= query options for a specific repo\n"), stream); fputs(_(" -v, --verbose always show directive names\n"), stream); fputs(_(" -l, --repo-list list configured repositories\n"), stream); + fputs(_(" -i, --is-set returns 0 (successful) if config flag is set\n"), stream); fputs(_(" -h, --help display this help information\n"), stream); fputs(_(" -V, --version display version information\n"), stream); cleanup(); @@ -58,7 +59,7 @@ static void parse_opts(int argc, char **argv) int c; config_file = CONFFILE; - const char *short_opts = "c:hlR:r:Vv"; + const char *short_opts = "c:h:i:lR:r:Vv"; struct option long_opts[] = { { "config" , required_argument , NULL , 'c' }, { "rootdir" , required_argument , NULL , 'R' }, @@ -67,6 +68,7 @@ static void parse_opts(int argc, char **argv) { "verbose" , no_argument , NULL , 'v' }, { "help" , no_argument , NULL , 'h' }, { "version" , no_argument , NULL , 'V' }, + { "is-set" , required_argument , NULL , 'i' }, { 0, 0, 0, 0 }, }; @@ -99,6 +101,9 @@ static void parse_opts(int argc, char **argv) cleanup(); exit(0); break; + case 'i': + check_name = optarg; + break; case '?': default: usage(1); @@ -391,6 +396,39 @@ static int list_directives(void) return ret; } +static int check_config_flags( void ) +{ + /* 1 = flag-not-set. Regardless of whether flag exists or not */ + int ret = 1; + short value; + + if (strcasecmp(check_name, "Color") == 0) { + value = config->color; + } else if (strcasecmp(check_name, "UseSyslog") == 0) { + value = config->usesyslog; + } else if (strcasecmp(check_name, "TotalDownload") == 0) { + value = config->totaldownload; + } else if (strcasecmp(check_name, "CheckSpace") == 0) { + value = config->checkspace; + } else if (strcasecmp(check_name, "VerbosePkgLists") == 0) { + value = config->verbosepkglists; + } else if (strcasecmp(check_name, "DisableDownloadTimeout") == 0) { + value = config->disable_dl_timeout; + } else if (strcasecmp(check_name, "ILoveCandy") == 0) { + value = config->chomp; + } else { + value = -1; + } + + if (value == -1) { + fprintf(stderr, _("error: unknown config option '%s'\n"), check_name); + ret = 1; + } else { + ret = !value; + } + return ret; +} + int main(int argc, char **argv) { int ret = 0; @@ -427,6 +465,8 @@ int main(int argc, char **argv) list_repos(); } else if(repo_name) { ret = list_repo_directives(); + } else if (check_name) { + ret = check_config_flags(); } else { ret = list_directives(); }