From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27913 invoked from network); 3 Feb 2021 15:47:38 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 3 Feb 2021 15:47:38 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1612367259; b=dFukXf28NzTAiLFszt7A7fuxY63I0K4ZPO05ZtkTvTpg7sSkuU40DbHd31D2SqlcPdNco66v+Z Hu3NbwWevQOPPCfbcF5y7k4h5LtDvxwTdgxqNO+O3ERpZd37PlIPEnvhmfQcnyWX6VzWEeuAp0 7XV88dLs/xmAzFHoRRvKQ58xgBF+EH0DisKaUtoS6PrFXNYpHr0wRVBeY/wl3WC7P1G0f9uWA4 s697nSittEjjYetRkaJsw+IsvKqNR7qdMG6uAjM3fv9PfCYSEAv99WL3Ysl2Zuz1NtVbRzp2ZA qGcEn/7hd/SYe1GsZRsjoX33Pj9L3bexLlDbzcSaITtmHg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1612367259; bh=fwp/S/YlDjytBdimE8z2joo0DMphEYUN1NAAo8fdfHU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:MIME-Version:Message-ID:Date: Subject:Cc:To:From:DKIM-Signature:DKIM-Signature; b=eVVKpdOxiAGc2tb9bFoj3oBbAB5gc7VP7l6S+ypQ1ts/uuSAGQPzHMkY/VBmovQ21iddqgF+fW nWau3f2arJHhXF8ylkWZwWZKTsUsCSn+JTLBNMJPtHGzbbdnC0wP0jetApmdAtF/OON2KwwC8V 9w8b87VTUFXEwNLque9NNlNkrUTEHDskS1u2HcHOB5Ou5C3jUozGVMdSBUteBOilSvrKEZ8vdh Uy0Z5/1YE9fVL6iqfAZ3H/mRHiPGbdEl0nQmeKmY5wmAXUfqhHOYmEQXvprOXiauCqqQZJvGH1 A1btKflbPCp3T18sXko6cnIfVBuB9DgfJ4evdj34blGghA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References; bh=Ic0/ij6X8RP/kAQ7nLj4EYKzT2LSdedPzEBv7D5zsZA=; b=bMr6dqbnvGLwboI+IfszJaV/UY 8d4eXdS8QyH+f2rokaUh97DOpp+JbQ2u/QnQKu1rUhDEN0C/rb/mvYrOb/75D0xk9R2tV2We6d2Ix V3vwFqBZLRmxfJdv2a4lmHK3k8+GLqbtz62khEidAJLGyRXFvRTtX2EctfpdC+qRE5syGvrFsrOiM PT5ykKm4cEtDC0wKYEtNpLxlFRGiDakz6WDooFpVosL9vKvDTKQ49n7n3dBXJEcwx6DB77ZTy7A6C xMiaUxFYIf9322qw552lH22mIz0Dg6PKYnc268JyXBGdfKode+shUitMBpgUQ2D+nruVl10yIiSJO 1DjMimDQ==; Received: from authenticated user by zero.zsh.org with local id 1l7KNU-000092-Kt; Wed, 03 Feb 2021 15:47:36 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f52.google.com ([209.85.167.52]:43055) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l7KNE-000Q0B-Bb; Wed, 03 Feb 2021 15:47:20 +0000 Received: by mail-lf1-f52.google.com with SMTP id d3so8062569lfg.10 for ; Wed, 03 Feb 2021 07:47:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ic0/ij6X8RP/kAQ7nLj4EYKzT2LSdedPzEBv7D5zsZA=; b=qHlqnN53LVtdFRLXp4wvT4k0k3NqMVjD7LyIl5cPv1SV5RDmJer1OuyG6W6WaYHdJU 5cDpJn67+FLQXhiP6VGZWJ9tUAIDeYpLaXXdbzlnkibWuwYv0Kokhih741zWk/vMKD2u +jj3VrFmvgaYzPwTJsPBDXvpypJDnC8srKTQ0Rg1rOae/0CyJ/HFzqzzQxXgHqhY5W8R g/QMBU/QOq3fnxFt7bWObyHmUkyAYD8mePuI7ASf/WQ25Kq21xptOsG5nMnCve/ryviV 347LCXCk3uIntxXZEJ8X8uXE73cm3DKN/w47D6u5m0rBC3TFZuUXgxZvMilP4rt+X2E0 rrEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ic0/ij6X8RP/kAQ7nLj4EYKzT2LSdedPzEBv7D5zsZA=; b=ps0DN5S0qa6xyOQXW7EOXHyNaDzyuGmBXheS/jklgPFvEB9BZ9Y80vy0hJVaegtFD7 neRpM4Se5f1mB4L1SqLHta8JU3tO5pIyIuCgmIJO/d6ufrXLS5sbTbKJRYr6cwS1ikFs 3xLNCFRy5t92K7Ye4jzKjQ0cezC0poyjd4QHpoO2QZ60wOodFNGsI9mkqUMWOMpy+KEk Hg+pRIfRLBj2qiTIpbk+rTvZ/c4xCb505OX/XX0mNFEWk+HgtemRemnKyOzp9MHgcec7 zwbZ4Cqi+fhCuDRWuo8/+YnOl5v5Ujfj99lwlLE8Pxwk31S3ZH01adFBe7IfHuB1GT1Z lJ1Q== X-Gm-Message-State: AOAM531YJAv41QI/DgA9X+j7ClZcvF2QU3k/dMe8mTrJlir8unAPJmLP 6run36OGzwo9j42S9W5vYdu1b1xHBrc= X-Google-Smtp-Source: ABdhPJzeul4dnT9nK4WyBUD4I/rqmhM48ARBEfDa2AJbF0ft7CLRyjOjNJn9ByIpJqEQw641Gt1zuw== X-Received: by 2002:ac2:592b:: with SMTP id v11mr2021501lfi.512.1612367239726; Wed, 03 Feb 2021 07:47:19 -0800 (PST) Received: from mail.gmail.com (25.37-191-153.fiber.lynet.no. [37.191.153.25]) by smtp.gmail.com with ESMTPSA id y23sm277280lfy.158.2021.02.03.07.47.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 07:47:19 -0800 (PST) From: Joshua Krusell To: zsh-workers@zsh.org Cc: Joshua Krusell Subject: [PATCH] Add leading '-' to zparseopts option parsing errors Date: Wed, 3 Feb 2021 16:46:59 +0100 Message-Id: <20210203154659.466091-1-js.shirin@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Seq: 47905 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: This only affects error messages associated with parsing positional parameters. Error messages from parsing option specs are kept as is without the leading dash to match how options are defined when calling zparseopts. --- This would be the new behaviour: % set -- -h % zparseopts -- h: zparseopts: no default array defined: h: % zparseopts -a foo -- h h zparseopts: option defined more than once: h % zparseopts -- h:=foo zparseopts: missing argument for option: -h I'm not sure this reduces ambiguity besides the example that Daniel mentioned earlier. % set -- --x % zparseopts -F -- x:=foo zparseopts: bad option: --x /Joshua Src/Modules/zutil.c | 8 ++++---- Test/V12zparseopts.ztst | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index c8017d0c0..cecea6d51 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -1874,9 +1874,9 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) if (!(d = sopts[STOUC(*o)])) { if (fail) { if (*o != '-') - zwarnnam(nam, "bad option: %c", *o); + zwarnnam(nam, "bad option: -%c", *o); else - zwarnnam(nam, "bad option: %s", o); + zwarnnam(nam, "bad option: -%s", o); return 1; } o = NULL; @@ -1889,7 +1889,7 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) } else if (!(d->flags & ZOF_OPT) || (pp[1] && pp[1][0] != '-')) { if (!pp[1]) { - zwarnnam(nam, "missing argument for option: %s", + zwarnnam(nam, "missing argument for option: -%s", d->name); return 1; } @@ -1916,7 +1916,7 @@ bin_zparseopts(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) else if (!(d->flags & ZOF_OPT) || (pp[1] && pp[1][0] != '-')) { if (!pp[1]) { - zwarnnam(nam, "missing argument for option: %s", + zwarnnam(nam, "missing argument for option: -%s", d->name); return 1; } diff --git a/Test/V12zparseopts.ztst b/Test/V12zparseopts.ztst index c41c49022..816e1d041 100644 --- a/Test/V12zparseopts.ztst +++ b/Test/V12zparseopts.ztst @@ -65,11 +65,11 @@ } $=1 done 0:zparseopts -F -?(anon):zparseopts:2: bad option: x +?(anon):zparseopts:2: bad option: -x >ret: 1, optv: , argv: -a -x -z -?(anon):zparseopts:2: bad option: x ->ret: 1, optv: , argv: -ax -z ?(anon):zparseopts:2: bad option: -x +>ret: 1, optv: , argv: -ax -z +?(anon):zparseopts:2: bad option: --x >ret: 1, optv: , argv: -a --x -z for 1 in '-a 1 2 3' '1 2 3'; do @@ -168,5 +168,5 @@ print -r - ret: $?, optv: $optv, argv: $argv } -ab1 -c 0:missing optarg -?(anon):zparseopts:2: missing argument for option: c +?(anon):zparseopts:2: missing argument for option: -c >ret: 1, optv: , argv: -ab1 -c -- 2.30.0