public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top, Paul Holzinger <pholzing@redhat.com>
Subject: Re: [PATCH v2] conf: Stop parsing options at first non-option argument
Date: Thu, 8 Aug 2024 06:02:28 +0200	[thread overview]
Message-ID: <20240808060228.03a33799@elisabeth> (raw)
In-Reply-To: <ZrQX9JwcpmyKWdhL@zatzit.fritz.box>

On Thu, 8 Aug 2024 10:57:24 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Wed, Aug 07, 2024 at 01:28:40PM +0200, Stefano Brivio wrote:
> > Given that pasta supports specifying a command to be executed on the
> > command line, even without the usual -- separator as long as there's
> > no ambiguity, we shouldn't eat up options that are not meant for us.
> > 
> > Paul reports, for instance, that with:
> > 
> >   pasta --config-net ip -6 route
> > 
> > -6 is taken by pasta to mean --ipv6-only, and we execute 'ip route'.
> > That's because getopt_long(), by default, shuffles the argument list
> > to shift non-option arguments at the end.
> > 
> > Avoid that by adding '-' at the beginning of 'optstring', and mark the
> > position of the first non-option argument (getopt_long() will now
> > return the character code 1 once we hit it), so that we can use that
> > as command to run, or as PID for the target namespace.
> > 
> > Reported-by: Paul Holzinger <pholzing@redhat.com>
> > Signed-off-by: Stefano Brivio <sbrivio@redhat.com>  
> 
> Eh... I'm kind of ambivalent about the idea.  I tend to think that
> accepting options in any position is generally expected behaviour, and
> anything programmatically adding commands to pasta should routinely
> insert a "--" (that's certainly what I do in testing code).

Sure, on the other hand it's convenient when you're quickly trying out
ip -6 route show, or some command where "--" would add 10% of typing or
so.

> But, that's not a particularly strong opinion, so whatever.
> 
> The implementation looks more complex than necessary, though.  AFAICT
> if you just add a '+' to the front of the optstring it will do exactly
> what you want without having to juggle the first_nonopt and other
> variables.

Oops, that's actually the first approach I considered, but I didn't see
any guarantee that optind would assume the expected value after the
loop. However, it does... sending v3.

-- 
Stefano


  reply	other threads:[~2024-08-08  4:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-07 11:28 [PATCH v2] conf: Stop parsing options at first non-option argument Stefano Brivio
2024-08-08  0:57 ` David Gibson
2024-08-08  4:02   ` Stefano Brivio [this message]
2024-08-08  4:43     ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240808060228.03a33799@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=pholzing@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).