Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #197577

Re: argsparse: allowing --version without mandatory options

Path csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Lawrence D’Oliveiro <ldo@nz.invalid>
Newsgroups comp.lang.python
Subject Re: argsparse: allowing --version without mandatory options
Date Thu, 30 Oct 2025 21:57:52 -0000 (UTC)
Organization A noiseless patient Spider
Lines 17
Message-ID <10e0n10$n2t$10@dont-email.me> (permalink)
References <87bjlod7g3.fsf@zedat.fu-berlin.de>
MIME-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
Injection-Date Thu, 30 Oct 2025 21:57:53 +0000 (UTC)
Injection-Info dont-email.me; posting-host="2b9c82400e22905b523c24ef2db6faaf"; logging-data="23645"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zct3jKXQfvVc2/Ko9ajit"
User-Agent Pan/0.164 (Kupiansk)
Cancel-Lock sha1:17wWuiIdyYvP/uBIoRt4gef1lo0=
Xref csiph.com comp.lang.python:197577

Show key headers only | View raw


On Thu, 30 Oct 2025 11:12:28 +0100, Loris Bennett wrote:

> I am writing a program for the command-line which uses 'argsparse'.  I
> want to make some options mandatory by setting 'required=True', but
> still allow the program to run with the option '--version' (which just
> shows the version and then exits) even if the mandatory options are
> missing.
>
> Is there a standard way of doing this?

Crusty curmudgeon here, still sticking to good old getopt. It may be
simple, crude even, but on the other hand it doesn’t try to do too
much. It may be “soft-deprecated”, but at least that means it will
keep on doing what it does for the foreseeable future.

It doesn’t offer built-in help, but then I also like to write man
pages (yes, proper documentation) for my more complex scripts.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar


Thread

argsparse: allowing --version without mandatory options "Loris Bennett" <loris.bennett@fu-berlin.de> - 2025-10-30 11:12 +0100
  Re: argsparse: allowing --version without mandatory options "Loris Bennett" <loris.bennett@fu-berlin.de> - 2025-10-30 13:50 +0100
    Re: argsparse: allowing --version without mandatory options "Jonathan N. Little" <lws4art@gmail.com> - 2025-11-03 22:19 -0500
  Re: argsparse: allowing --version without mandatory options Lawrence D’Oliveiro <ldo@nz.invalid> - 2025-10-30 21:57 +0000

csiph-web