Proposed argument changes to ntpq (fixing bug #319)

Gary E. Miller gem at
Thu Jun 8 22:29:43 UTC 2017

Yo Ian!

On Thu, 8 Jun 2017 15:29:19 -0500
Ian Bruene via devel <devel at> wrote:

> >> "A <colon> (':') shall be returned if getopt() detects a missing
> >> argument and the first character of optstring was a <colon> (':')."
> >>
> >> So optional optarg can be valid POXIX.  
> > I didn't know that.  Thanks.  
> Unfortunately the documentation / StackOverflow questions / library
> code I've been able to find indicate that this feature does not exist
> in python's getopt.

NTPsec does not use Python's getopt().  It uses argparse().

Of interest is Argumentparser.add_argument():

Check out the second bullit under nargs:

"'?'. One argument will be consumed from the command line if possible,
and produced as a single item. If no command-line argument is present,
the value from default will be produced. "

Then example code for what I suggested.

Simplied example code here:

>>> import argparse
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--foo', nargs='?', const='c', default='d')
_StoreAction(option_strings=['--foo'], dest='foo', nargs='?', const='c', default='d', type=None, choices=None, help=None, metavar=None)
>>> parser.parse_args(['--foo', 'YY'])
>>> parser.parse_args(['--foo'])

Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
	gem at  Tel:+1 541 382 8588

	    Veritas liberabit vos. -- Quid est veritas?
    "If you can’t measure it, you can’t improve it." - Lord Kelvin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the devel mailing list