Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 51256 - Command Line Parsing Error --action vs action
Summary: Command Line Parsing Error --action vs action
Status: RESOLVED WONTFIX
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Interface (emerge) (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-17 01:11 UTC by Michael Stewart (vericgar) (RETIRED)
Modified: 2005-08-12 22:53 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Quick one liner (emerge-two-action.patch,385 bytes, patch)
2005-08-06 08:20 UTC, Alec Warner (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Stewart (vericgar) (RETIRED) gentoo-dev 2004-05-17 01:11:47 UTC
The logic in parsing the command line is different based on whether you use --action or just action. In specific, if you use --rsync you get an error about being deprecated while when using rsync you don't. Also, if you specify multiple actions on the command line, if the second action specified does is not specified with -- before it the check to see if multiple actions are specified is skipped.

Reproducible: Always
Steps to Reproduce:
(4 different tests here)

1) emerge -p --clean --info
2) emerge -p --clean info
3) emerge -p clean --info
4) emerge -p --clean info
Actual Results:  
1 and 3) correct behavoir
2 and 4) incorrect behavoir (trys to perform the command)
>>> These are the packages that I would unmerge:

--- Couldn't find info to clean.

>>> clean: No packages selected for removal.


In portage 2.0.50-r6, emerge:

line 179:
    elif (not myaction) and (x in actions):

line 187: (still in the condition from line 179)
        if myaction:

the block under line 187 can never be reached because the same test is performed
at line 179.
Comment 1 Michael Stewart (vericgar) (RETIRED) gentoo-dev 2005-07-28 23:40:02 UTC
As this was recently mentioned on the IRC channel wondering if this was a valid
bug or not, let me provide some more examples and the vastly different output
for them. 

Here's another, better example (i.e. one using actions that don't take a
package-name):

Case 1:
vericgar@phoenix ~ $ emerge -p sync --info

!!! Multiple actions requested... Please choose one only.
!!! '--sync' or '--info'

Case 2:
vericgar@phoenix ~ $ emerge -p sync info
emerge: "sync" actions do not support "--pretend."

Case 3:
vericgar@phoenix ~ $ emerge -p --sync info
emerge: "sync" actions do not support "--pretend."

Case 4:
vericgar@phoenix ~ $ emerge -p --sync --info

!!! Multiple actions requested... Please choose one only.
!!! '--sync' or '--info'

Case 5:
vericgar@phoenix ~ $ emerge -p info sync    
Portage 2.0.51.22-r1 (default-linux/x86/2005.0, gcc-3.3.5-20050130,
glibc-2.3.4.20041102-r1, 2.6.11-gentoo-r4 i686)
=================================================================
System uname: 2.6.11-gentoo-r4 i686 Pentium III (Cascades)
Gentoo Base System version 1.6.12
ccache version 2.3 [enabled]
dev-lang/python:     2.3.5
sys-apps/sandbox:    1.2.10
sys-devel/autoconf:  2.13, 2.59-r6
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.5
sys-devel/binutils:  2.15.92.0.2-r10
sys-devel/libtool:   1.5.18-r1
virtual/os-headers:  2.6.11-r2
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer -mfpmath=sse"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config
/usr/lib/X11/xkb /usr/share/config /usr/share/texmf/dvipdfm/config/
/usr/share/texmf/dvips/config/ /usr/share/texmf/tex/generic/config/
/usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer -mfpmath=sse"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig buildpkg ccache collision-protect cvs digest
distlocks fixpackages keeptemp keepwork nostrip sandbox severe sfperms strict
test userpriv usersandbox"
GENTOO_MIRRORS="ftp://mirrors.tds.net/gentoo
http://mirror.cpsc.ucalgary.ca/mirror/gentoo.org http://lug.mtu.edu/gentoo/
http://gentoo.llarian.net/"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/distfiles/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/home/vericgar/portage-overlay/cvs-tree/gentoo-x86
/home/vericgar/portage-overlay/work-tree"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
USE="x86 berkdb crypt doc gdbm makecheck mmx ncurses nptl pam python readline
sse ssl unicode userland_GNU kernel_linux elibc_glibc"
Unset:  ASFLAGS, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS

Case 6:
vericgar@phoenix ~ $ emerge -p --info sync
Portage 2.0.51.22-r1 (default-linux/x86/2005.0, gcc-3.3.5-20050130,
glibc-2.3.4.20041102-r1, 2.6.11-gentoo-r4 i686)
=================================================================
System uname: 2.6.11-gentoo-r4 i686 Pentium III (Cascades)
Gentoo Base System version 1.6.12
ccache version 2.3 [enabled]
dev-lang/python:     2.3.5
sys-apps/sandbox:    1.2.10
sys-devel/autoconf:  2.13, 2.59-r6
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.5
sys-devel/binutils:  2.15.92.0.2-r10
sys-devel/libtool:   1.5.18-r1
virtual/os-headers:  2.6.11-r2
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer -mfpmath=sse"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config
/usr/lib/X11/xkb /usr/share/config /usr/share/texmf/dvipdfm/config/
/usr/share/texmf/dvips/config/ /usr/share/texmf/tex/generic/config/
/usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d"
CXXFLAGS="-march=pentium3 -O3 -pipe -fomit-frame-pointer -mfpmath=sse"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs autoconfig buildpkg ccache collision-protect cvs digest
distlocks fixpackages keeptemp keepwork nostrip sandbox severe sfperms strict
test userpriv usersandbox"
GENTOO_MIRRORS="ftp://mirrors.tds.net/gentoo
http://mirror.cpsc.ucalgary.ca/mirror/gentoo.org http://lug.mtu.edu/gentoo/
http://gentoo.llarian.net/"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/distfiles/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/home/vericgar/portage-overlay/cvs-tree/gentoo-x86
/home/vericgar/portage-overlay/work-tree"
SYNC="rsync://rsync.namerica.gentoo.org/gentoo-portage"
USE="x86 berkdb crypt doc gdbm makecheck mmx ncurses nptl pam python readline
sse ssl unicode userland_GNU kernel_linux elibc_glibc"
Unset:  ASFLAGS, CTARGET, LANG, LC_ALL, LDFLAGS, LINGUAS

Case 7:
vericgar@phoenix ~ $ emerge -p --info --sync

!!! Multiple actions requested... Please choose one only.
!!! '--info' or '--sync'

Case 8:
vericgar@phoenix ~ $ emerge -p info --sync

!!! Multiple actions requested... Please choose one only.
!!! '--info' or '--sync'

The bug in cases 2,3,5,6 is that it's getting *past* the code to check if more
then one action was specified and not erroring out. This is because actions with
-- in front of them are handled differently then actions without that.

A clue to this if you look at emerge for the portage 2.0.51.22-r1, on line 266
you see the following block:

    elif (not myaction) and (x in actions):
        if x not in ["system", "world"]:
            [....]
        if myaction:
            print
            print red("!!!")+green(" Multiple actions requested... Please choose
one only.")
            print red("!!! '")+darkgreen(myaction)+"' "+red("or")+"
'"+darkgreen(x)+"'"
            print
            sys.exit(1)

Note the if (not myaction) and then if myaction being in the run-if-true block.
It's not possible to have not myaction && myaction to be true.

When I'm more awake I may look into creating a patch for this. The sticky
situation is that the action may match a package name and you would want to
treat it as a package instead of an action. Maybe another list can be created of
actions that take a arguments and those that don't - the ones that do take an
argument would take the second action as an argument. Though I wonder how
difficult it would be to chain actions and do them all (which is what any user
specifying more then one action at a time is probably expecting).
Comment 2 Alec Warner (RETIRED) archtester gentoo-dev Security 2005-08-06 08:20:21 UTC
Created attachment 65239 [details, diff]
Quick one liner

I've retested all the cases given and it works for all of them.  I've also
tested normal operation and have found no issues with just taking that test
out. Please test it locally and make sure that it works for you :)
Comment 3 Alec Warner (RETIRED) archtester gentoo-dev Security 2005-08-12 22:53:41 UTC
From gentoo-portage-dev-ML via Jason:
This patch will mean that it's impossible to do things like 'emerge -s sync'

In my opinion, the behaviour of all those test cases listed in that bug is 
correct. The first non-double-dashed parameter that names an action is 
taken to be the requested action. Adding the double-dash explicitly makes 
the parameter refer to an action. All the test cases show those two rules 
to be working correctly.

Searching is a quirky one, if you have say emerge --search sync, you want to 
search the tree for stuff dealing with sync, not die out because the user 
specified two actions.  In order to make it so that emerge --sync info is bad 
but emerge --search sync requires too much complexity to even bother with.  You 
end up taking generic parsing code and making exceptions in it which tends to 
make the code less maintainable.  Besides Jason has a point, it's not 
particularly a problem the way it is.