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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2771 invoked from network); 21 Sep 2021 15:21:55 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Sep 2021 15:21:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date: Content-Transfer-Encoding:Content-ID:Content-Type:MIME-Version:Subject:To: References:From:In-reply-to:cc:Reply-To:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=IG41hAgpSO5aCaiqWG4MaOe/+uve6TC/LQyYxYT6EKk=; b=Izt0uZXDj9bGKUe6xpfXAN8RL4 BDZvoU0fIsOxZio/qoTblEKE4PHprtLcEGcCZOT64plO6O9jVgWHLWP8BpNX2WkrZ3sjIg4Twylqp m0EF2RxNAWK5+ADKXb+yT1X4z/Nn2kCfaLaQm63aQRQofI78TKZicj/B/ouaV9HQsBKHtKcKiLMdX 2R3sJkS5wUzFLSCGyaGXCRZRCfhxNO31LK67b+YcAK2tZt2VjoEZ/PHEGXX7DS3tqldShpXP8hGUZ vvDu+vnYFO3zwyGz96nsuhIwfOGfntlQA1J6bKBAFcmJYLQ95Th9sUxleDXppIKsXnNMh85Sz3gBD yxSGqAYw==; Received: from authenticated user by zero.zsh.org with local id 1mShaj-000Lb0-Q3; Tue, 21 Sep 2021 15:21:53 +0000 Received: from authenticated user by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mShZl-000Ks5-KL; Tue, 21 Sep 2021 15:20:53 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.94.2) (envelope-from ) id 1mShZk-000076-8H; Tue, 21 Sep 2021 17:20:52 +0200 cc: zsh-users@zsh.org In-reply-to: From: Oliver Kiddle References: To: Eric Cook Subject: Re: When to (and not to) use _arguments -C with states MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <438.1632237652.1@hydra> Content-Transfer-Encoding: 8bit Date: Tue, 21 Sep 2021 17:20:52 +0200 Message-ID: <439-1632237652.253313@73O7.mb_i.71xZ> X-Seq: 27128 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Eric Cook wrote: > I think that i mostly already figured it out but this piece of zshcompsys(1) always confused me. > > Where _arguments encounters action in the `->string' format, it will strip all leading and trailing whitespace from string and > set the array state to the set of all strings for which an action is to be performed. The elements of the array state_descr > are assigned the corresponding message field from each optarg containing such an action. > > In the majority of completers that i have written that used ->string actions, only one action was > `action`able at a given time. meaning $state is only a single element, with code that assumes as much like: In the vast majority of cases this is true – which allows you to pass -C and have it modifiy $curcontext instead of needing to pick out the correct element of $context. > Which made me question when is multiple ->string actions possible? > > An contrived example being: This is probably the most obvious case – optional arguments in conjunction with normal arguments. Fortunately even that is rare. Optional arguments often require an = or no space between option and argument. It is also fairly easy to contrive cases using the sets feature of _arguments, e.g something like: _arguments - first '-f' '1:foo' - second '-f:bar' Sets with overloaded options does happen and can require a little care (and sometimes the application of _guard for numeric arguments). You can also get into the question of normal arguments that look like options. _arguments doesn't always handle that perfectly but given that argument parsing libraries generally don't cope either it isn't really something we need to worry about. The rare cases where you can't use _arguments -C are usually fairly obvious. It tends to be otherwise apparent that they've got weird argument parsing to begin with. For some such things, _regex_arguments can be a better choice. Oliver