Project

General

Profile

Actions

Bug #603

closed

lttng-bash_completion out of sync, includes an error

Added by Daniel U. Thibault over 10 years ago. Updated over 10 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Target version:
Start date:
07/25/2013
Due date:
% Done:

30%

Estimated time:

Description

As of lttng-tools-2.3.0-rc2-6-81ea21b, lttng-bash_completion has gotten out of sync with the lttng command-line interface: it handles two obsolete commands and omits a new one. There is also an error in one of the blocks.

Line 23:

_lttng_cmd_add_context() {
    local add_context_opts
    add_context_opts=$(lttng add-context --list-options)

    case $prev in
    --session|-s)
        _lttng_complete_sessions
        return
        ;;
    --channel|-c)
        return
        ;;
    --event|-e)
        return
        ;;
    --type|-t)
        return
        ;;
    esac

    case $cur in
    -*)
        COMPREPLY=( $(compgen -W "${add_context_opts}" -- $cur) )
        return
        ;;
    esac
}

The add-context command does not accept an --event option.

line 131:

_lttng_cmd_enableconsumer() {
    local enable_consumer_opts
        enable_consumer_opts=$(lttng enable-consumer --list-options)

    case $prev in
    --session|-s)
        _lttng_complete_sessions
        return
        ;;
    esac

    case $cur in
    -*)
        COMPREPLY=( $(compgen -W "${enable_consumer_opts}" -- $cur) )
        return
        ;;
    esac
}

The enable-consumer command has been withdrawn.

line 150:

_lttng_cmd_disableconsumer() {
    local disable_consumer_opts
        disable_consumer_opts=$(lttng disable-consumer --list-options)

    case $prev in
    --session|-s)
        _lttng_complete_sessions
        return
        ;;
    esac

    case $cur in
    -*)
        COMPREPLY=( $(compgen -W "${disable_consumer_opts}" -- $cur) )
        return
        ;;
    esac
}

The disable-consumer command has been withdrawn.

line 169:

_lttng_cmd_disable_event() {
    local disable_event_opts
    disable_channel_opts=$(lttng disable-event --list-options)

    case $prev in
    --session|-s)
        _lttng_complete_sessions
        return
        ;;
    --channel|-c)
        return
        ;;
    esac

    case $cur in
    -*)
        COMPREPLY=( $(compgen -W "${disable_event_opts}" -- $cur) )
        return
        ;;
    esac
}

Note the copy-paste error on line 171.

At line 240, a block needs to be added to cover the new snapshot command.

Actions #1

Updated by Daniel U. Thibault over 10 years ago

Actually, lttng --list-commands still returns enable-consumer and disable-consumer, so the _lttng_cmd_*able_consumer() should be kept but their case $prev can be removed.

I also find command-line completion fails for the enable-channel, enable-event and disable-channel commands because it is looking for e.g. _lttng_cmd_enable_channel but lttng-bash_completion supplies _lttng_cmd_enablechannel.

Actions #2

Updated by Daniel U. Thibault over 10 years ago

Here is a crude _lttng_complete_sessions():

_lttng_complete_sessions() {
    # TODO, maybe have a lttng list --simple or something like that
    local sessions_opts
#    sessions_opts=$(lttng list --simple)
    sessions_opts=$(lttng list | cut -s -d")" -f2 | cut -d"(" -f1)
    COMPREPLY=( $(compgen -W "${sessions_opts}" -- $cur) )
    return
}

The generated sessions_opts contains extra blanks on either side of the session names, but bash completion takes care of those.

And here is a crude _lttng_cmd_snapshot():

_lttng_cmd_snapshot() {
    local snapshot_opts
    snapshot_opts=$(lttng snapshot --list-options)
    # TODO We need a 'snapshot --list-actions' to get the list of possible actions
    local snapshot_acts
#    snapshot_acts=$(lttng snapshot --list-actions)
    snapshot_acts="add-output del-output list-output record" 

    case $prev in
    --session|-s)
        _lttng_complete_sessions
        return
        ;;
    esac

    case $cur in
    -*)
        COMPREPLY=( $(compgen -W "${snapshot_opts}" -- $cur) )
        return
        ;;
    *)
        COMPREPLY=( $(compgen -W "${snapshot_acts}" -- $cur) )
        return
        ;;
    esac
}

Until lttng snapshot --list-actions is implemented, this lttng-bash_completion function will need to be manually updated every time a snapshot action is renamed, added or deleted.

Finally, I would add a call to _lttng_complete_sessions in _lttng_cmd_list() and _lttng_cmd_set_session():

_lttng_cmd_list() {
    local list_opts
    list_opts=$(lttng list --list-options)

    case $prev in
    --channel|-c)
        return
        ;;
    esac

    case $cur in
    -*)
        COMPREPLY=( $(compgen -W "${list_opts}" -- $cur) )
        return
        ;;
    *)
        _lttng_complete_sessions
        ;;
    esac
}

_lttng_cmd_set_session() {
    local set_session_opts
    set_session_opts=$(lttng set-session --list-options)

    case $cur in
    -*)
        COMPREPLY=( $(compgen -W "${set_session_opts}" -- $cur) )
        return
        ;;
    *)
        _lttng_complete_sessions
        ;;
    esac
}

It may also make sense to add a similar call to _lttng_complete_sessions in _lttng_create(), just so the user knows which session names are already taken.

Actions #3

Updated by Daniel U. Thibault over 10 years ago

My proposal for _lttng_complete_sessions() above works fine with the local session daemon, but it will not give the correct session listing when using 'sudo -H lttng ...' because the $(lttng list | cut ...) command is not run as root. For example, if the local daemon has a 'local' session and the root daemon has a 'kernel' session, auto-completion of 'sudo -H list' will propose just 'local'.

The funny thing is, this "bug" would also crop up if we had an lttng list --simple implementation. It is probably unfixable because bash auto-completion is not aware that the user intends to use 'sudo' ($COMP_CWORDS[0] returns 'lttng').

Actions #4

Updated by Christian Babeux over 10 years ago

  • Assignee set to Simon Marchi
Actions #5

Updated by Simon Marchi over 10 years ago

  • % Done changed from 0 to 30

I wrote some fixes for the most obvious stuff. For the rest, I'd rather write something clean than process formatted text. When I have some spare time I'll look into doing the sessions and snapshot stuff.

For reference, I submitted a patch a while back for a --simple in the list cmd: http://lists.lttng.org/pipermail/lttng-dev/2012-June/018153.html.

Actions #6

Updated by David Goulet over 10 years ago

  • Project changed from LTTng to LTTng-tools
  • Status changed from New to Confirmed
Actions #7

Updated by David Goulet over 10 years ago

  • Status changed from Confirmed to Resolved
Actions

Also available in: Atom PDF