From patchwork Thu Oct 7 10:59:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12541581 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDF57C433FE for ; Thu, 7 Oct 2021 11:00:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B7EB660F58 for ; Thu, 7 Oct 2021 11:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241103AbhJGLBy (ORCPT ); Thu, 7 Oct 2021 07:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241037AbhJGLBd (ORCPT ); Thu, 7 Oct 2021 07:01:33 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB04FC06177C for ; Thu, 7 Oct 2021 03:59:21 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id m22so17895455wrb.0 for ; Thu, 07 Oct 2021 03:59:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=HBNrd8h57EHcdKdkPIOTjFextPdmOMJpWyQiiEj8UK8=; b=AfjQviz+f0ERne/L/DYtjD7LME0F261U2q4zqA2/gkdkfXT8M9sXLSuoNMuUTdWhbq aHPb5JKJVH6JlPYG4CVndAI3D5+fLdbyi5wlaIy/usgDK4gD4WWYoEOVJ9+JJIufP0BS lElYer92zuldDmOC7XjlrdKjhxAkxTU0P7umLBibWHT6oL4RkaI5zarUpmsHUczwW1Lk Ledvy5FIIt1Zr3h/2crirGdZXm7dsdJbIagkgovbEzN0Gq8FDCFplOetqLR1B9Oc5Wc3 Idu/Qt1ERBzE39WpX6dXq2DUCK+aQV1ua9YTb/5l9pDGE/V/PLW4hHTiqLQVmrbLBaCd V5Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=HBNrd8h57EHcdKdkPIOTjFextPdmOMJpWyQiiEj8UK8=; b=PVNprEQrSU66wXeE5lF4juBKyrMFHE6ZVthDEFcVbcA4UUxxrgfO9jvdKw2xCmDXKp HXlxk5IVZ4DSwDGxON7ha3IxzmcnFLebEKhCB2WJdf8oDIgRb0CuDVSvIkFLwOCyb+5W 5DIjMhZSaWnHhEoZzJzksbhy6iwtY8qPYEbUysHmsbFaYkv/sdbHd0xyzasAwSZxEYg3 lKPDBLK3wWl5McDlANklgMA/Oo2chkKsjiYwigvSfZUoXNCdQzDOa1fZGAxw94zLsAP8 2Yg9kpW+3ArlXX34FCa0Eyfk8tr+sH9mDHmsJrZKgRhX37X84EXBNVvPRpQgbH9v0RMX Jghw== X-Gm-Message-State: AOAM530He5HnZXCGyqRKZTK0DnF3Nq6BlNSb7+E3e7oYUF7NsrHye5pQ Phhs/Z5UqBLb8msCJX6ns8zLij9U5Z0= X-Google-Smtp-Source: ABdhPJzezEkLDGjmy+8uTprBNFTR4pIvZn4KYMeJl9uiC7oaBCTLvNTprpUpR0jX8IJh8ZAZEQIsTw== X-Received: by 2002:a1c:f002:: with SMTP id a2mr15425519wmb.79.1633604360426; Thu, 07 Oct 2021 03:59:20 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m14sm7765523wmi.47.2021.10.07.03.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:59:20 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 07 Oct 2021 10:59:09 +0000 Subject: [PATCH v5 15/15] scalar: accept -C and -c options before the subcommand Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Derrick Stolee , Eric Sunshine , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Elijah Newren , Bagas Sanjaya , Theodore Ts'o , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin The `git` executable has these two very useful options: -C : switch to the specified directory before performing any actions -c =: temporarily configure this setting for the duration of the specified scalar subcommand With this commit, we teach the `scalar` executable the same trick. Signed-off-by: Johannes Schindelin --- contrib/scalar/scalar.c | 22 +++++++++++++++++++++- contrib/scalar/scalar.txt | 10 ++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/contrib/scalar/scalar.c b/contrib/scalar/scalar.c index b2e92cf63b5..6c496318bd4 100644 --- a/contrib/scalar/scalar.c +++ b/contrib/scalar/scalar.c @@ -807,6 +807,25 @@ int cmd_main(int argc, const char **argv) struct strbuf scalar_usage = STRBUF_INIT; int i; + while (argc > 1 && *argv[1] == '-') { + if (!strcmp(argv[1], "-C")) { + if (argc < 3) + die(_("-C requires a ")); + if (chdir(argv[2]) < 0) + die_errno(_("could not change to '%s'"), + argv[2]); + argc -= 2; + argv += 2; + } else if (!strcmp(argv[1], "-c")) { + if (argc < 3) + die(_("-c requires a = argument")); + git_config_push_parameter(argv[2]); + argc -= 2; + argv += 2; + } else + break; + } + if (argc > 1) { argv++; argc--; @@ -817,7 +836,8 @@ int cmd_main(int argc, const char **argv) } strbuf_addstr(&scalar_usage, - N_("scalar []\n\nCommands:\n")); + N_("scalar [-C ] [-c =] " + " []\n\nCommands:\n")); for (i = 0; builtins[i].name; i++) strbuf_addf(&scalar_usage, "\t%s\n", builtins[i].name); diff --git a/contrib/scalar/scalar.txt b/contrib/scalar/scalar.txt index 6fc57707718..3a80f829edc 100644 --- a/contrib/scalar/scalar.txt +++ b/contrib/scalar/scalar.txt @@ -36,6 +36,16 @@ The `scalar` command implements various subcommands, and different options depending on the subcommand. With the exception of `clone`, `list` and `reconfigure --all`, all subcommands expect to be run in an enlistment. +The following options can be specified _before_ the subcommand: + +-C :: + Before running the subcommand, change the working directory. This + option imitates the same option of linkgit:git[1]. + +-c =:: + For the duration of running the specified subcommand, configure this + setting. This option imitates the same option of linkgit:git[1]. + COMMANDS --------