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=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26710 invoked from network); 31 Jul 2021 22:05:12 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 31 Jul 2021 22:05:12 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 484E79CA60; Sun, 1 Aug 2021 08:05:09 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 9FC1E9C9B4; Sun, 1 Aug 2021 08:04:54 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=iitbombay-org.20150623.gappssmtp.com header.i=@iitbombay-org.20150623.gappssmtp.com header.b="yMPEAmpx"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id DFF719C9B4; Sun, 1 Aug 2021 08:04:52 +1000 (AEST) Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by minnie.tuhs.org (Postfix) with ESMTPS id 8709B9C9B2 for ; Sun, 1 Aug 2021 08:04:51 +1000 (AEST) Received: by mail-qk1-f175.google.com with SMTP id c9so13056347qkc.13 for ; Sat, 31 Jul 2021 15:04:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iitbombay-org.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Kjm9BOvzj8xWy5T4RREJ9bzwVpcb/ZLpogR/Es4hVIU=; b=yMPEAmpxhDaWt1OwGEM4cH5Vhl6OBUB9Q7PJh2QEKDGvVNFJTQJ8dKL1Evqaz6FR2B aZxbwtuhltXBilgmw1O8kR4pzKvuJuFuU54bdr7DB5PehH5My9xCzuxCHMYcuYTK8cQo FtHSFh08CEu68VMoce58IooMizQUwQig5QG6jZO1St3DIMJt7tY3EgNM1KaKgpAELRJu k0rq/TUECp6FfZrjIONOxDzujwCymlHtL/PNdeJbo611i0Hp5gFYL/4rX6hj6n8eovbE oKZ09vD+tUWxcGIZV94pjrxuslCymI4B593cg0nm1DnogzBi2npz4h6RJLkCh52dX95Q qrvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Kjm9BOvzj8xWy5T4RREJ9bzwVpcb/ZLpogR/Es4hVIU=; b=dT/nzv2zJ0AR1Pjh1yhFqRuks+YYJjnolfeM69OJeS06DbRrC3WVotj30UhgD1UFUN QMc/H0Gwmclbi1o2kIEppJdLOYEhRM0ZuhAIFUE4bci8JjkVR5HLW0JZTT9iopWLC85P dSrP7tObfDoAiiAf1d5ltw5fTG3/eOmlPRriEWYpP6GuFDCy7wFbpn9GMUlRp4RTjfzk XLZavbDroXE+GSneBgk4qGP3qBCUjdf9bVyUlzoBewH58kzH2rfNxrmTpJXwwKGxDKhY eW4UNJ6BN/2m2GPOqwf92vl5pJ3mlUXupKu9XZR/9rRqNr6F+7Qb+4PsxErKp9pq89UW GwWw== X-Gm-Message-State: AOAM532CXSbXu7CvVXC/mRBSxobAP/816n52yL9L912yvu1/Qie0PNRD 7RI+S44dTcRGLmw1AcIZTuHWdStfxDluRqW2 X-Google-Smtp-Source: ABdhPJxqejzbFO95Z7ITgrvBBS1ruzlP78fX8D9Nz3PmVbi03B1l4+v8muUwD9wFBysp3fdZiF1woQ== X-Received: by 2002:a37:40c2:: with SMTP id n185mr8091061qka.50.1627769090572; Sat, 31 Jul 2021 15:04:50 -0700 (PDT) Received: from smtpclient.apple (107-215-223-229.lightspeed.sntcca.sbcglobal.net. [107.215.223.229]) by smtp.gmail.com with ESMTPSA id a11sm3084746qkl.125.2021.07.31.15.04.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Jul 2021 15:04:50 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) From: Bakul Shah In-Reply-To: <202107311920.16VJK2jT2362871@fourwinds.com> Date: Sat, 31 Jul 2021 15:04:48 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <3598EE71-E652-43EF-B1AB-91CB8B3D577A@iitbombay.org> References: <20210731142533.69caf929@moon> <202107311920.16VJK2jT2362871@fourwinds.com> To: Jon Steinhart X-Mailer: Apple Mail (2.3654.120.0.1.13) Subject: Re: [TUHS] Systematic approach to command-line interfaces [ meta issues ] X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: TUHS main list Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" On Jul 31, 2021, at 12:20 PM, Jon Steinhart wrote: >=20 > So I never got getopt(). One of my rules is that I don't use a = library > in cases where the number of lines of gunk that that it takes to use a > library function is >=3D the number of lines to just write it myself. = Yeah, > I know the "but the library has more eyeballs and is debugged" = argument > but in reality libraries are the source of many bugs. I've always = taken > the approach that I would never hire someone who had to use a library = to > implement a singly-linked list. getopt() is perhaps the wrong solution but consider something like MH, whose commands all follow a common pattern. Consider: - options (switches) all start with a single '-' - they may be abbreviated to a unique prefix. - Boolean options may be inverted by prepending -no (e.g. -nolist) - value options may also have -no format to remove a previous (or = default) value - options may appear anywhere and the last instance wins But different commands take different options. It would make sense to = factor out common parsing, help etc. for a consistent treatment. In my Go code = for parsing MH like options I used Go's flag package as a model. Personally I vastly prefer MH style option processing to either single = char options or --very-long-names which can't be abbreviated. Never mind = options for commands like gcc, who can even remember 40+ ls options? But I haven't thought about how to extend this for shell scripts, or exposing these so that shells like zsh can do command completion. To = specify these you need a vector of tuples (name, type, default, brief-help) but = that is painful to do in a shell.