Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 154511

Summary: [Tracker] Add --brief for programmatic use
Product: Gentoo Hosted Projects Reporter: Donnie Berkholz (RETIRED) <dberkholz>
Component: eselectAssignee: Gentoo eselect Team <eselect>
Status: RESOLVED FIXED    
Severity: enhancement CC: esigra
Priority: High Keywords: Tracker
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on: 214817, 292097, 292099, 292100, 292101, 292102, 292104, 292105, 292107, 292108, 292109, 292111, 292112, 292113, 292115, 292116, 292117, 292119, 292120, 292121, 292122    
Bug Blocks:    

Description Donnie Berkholz (RETIRED) gentoo-dev 2006-11-08 15:55:04 UTC
It would be helpful for eselect to have an output mode that doesn't flood the screen when you want to use the output in some sort of script or program.

This would cause a command like `eselect --no-color --quiet lapack list` to simply list the installed implementations, avoiding list headers, numbering, and the little '*' next to the active implem, since that's accessible via the 'show' action. This way, the output could easily be read into, e.g.,  an array.
Comment 1 Danny van Dyk (RETIRED) gentoo-dev 2007-03-20 03:04:57 UTC
This will be one of the targets for 1.2.x line.
Comment 2 Ulrich Müller gentoo-dev 2009-04-21 06:13:09 UTC
The option should be called --brief not --quiet if we follow GNU coding standards.
Comment 3 Ulrich Müller gentoo-dev 2009-04-23 06:51:48 UTC
At the moment I don't see how this could be implemented other than on a module-by-module basis. The "list" action in modules typically looks like this (from kernel.eselect, but others are similar):

do_list() {
    targets=( $(find_targets ) )
    write_list_start "Available kernel symlink targets:"
    if [[ -n ${targets[@]} ]] ; then
        local i
        for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do
            [[ ${targets[${i}]} == \
                $(basename $(canonicalise ${ROOT}/usr/src/linux)) ]] && \
                targets[${i}]="${targets[${i}]} $(highlight '*' )"
        done
        write_numbered_list "${targets[@]}"
    else
        write_kv_list_entry "(none found)" ""
    fi
}

Changing the output routines to suppress list headings and numbering helps a little, but the "*" for the active target is added by the module. Also, the "non found" for an empty list should be suppressed, but is output by the module.
Comment 4 Ulrich Müller gentoo-dev 2009-08-19 11:12:03 UTC
The --brief option will be available in eselect-1.2 as an experimental feature. For most modules it produces reasonable results, but YMMV.

(In reply to comment #3)
> Changing the output routines to suppress list headings and numbering helps a
> little, but the "*" for the active target is added by the module.

There's now a "highlight_marker" function that modules can call for adding the "*", and it will suppress it in brief output mode. See doc/developer-guide.txt for details.
Comment 5 Ulrich Müller gentoo-dev 2009-11-06 09:52:20 UTC
> (In reply to comment #3)
> There's now a "highlight_marker" function that modules can call for
> adding the "*", and it will suppress it in brief output mode.
> See doc/developer-guide.txt for details.

Now that eselect-1.2.3 is marked stable on all architectures, it's time to fix the modules. This bug will be used as a tracker.

The following example (from kernel.eselect) illustrates what sort of changes should be done for most modules:

Function do_list() in eselect-1.1*:

  do_list() {
      local i targets=( $(find_targets) )
      write_list_start "Available kernel symlink targets:"
      if [[ ${#targets[@]} -gt 0 ]]; then
          for (( i = 0; i < ${#targets[@]}; i++ )); do
              [[ ${targets[i]} = \
                  $(basename "$(canonicalise "${ROOT}/usr/src/linux")") ]] \
                  && targets[i]="${targets[${i}]} $(highlight '*')"
          done
          write_numbered_list "${targets[@]}"
      else
          write_kv_list_entry "(none found)" ""
      fi
  }

and in eselect-1.2*, with changes for proper support for "brief" output mode:

  do_list() {
      local i targets=( $(find_targets) )
      write_list_start "Available kernel symlink targets:"
      for (( i = 0; i < ${#targets[@]}; i++ )); do
          [[ ${targets[i]} = \
              $(basename "$(canonicalise "${ROOT}/usr/src/linux")") ]] \
              && targets[i]=$(highlight_marker "${targets[i]}")
      done
      write_numbered_list -m "(none found)" "${targets[@]}"
  }

Please note:
- use of the "highlight_marker" function which replaces explicit highlight
- use of the "-m" option of "write_numbered_list" which automatically takes
  care of the empty list case
Comment 6 Ulrich Müller gentoo-dev 2013-03-11 15:36:33 UTC
All blockers have been fixed. Closing.