From patchwork Mon Feb 6 13:19:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yotam Gigi X-Patchwork-Id: 724490 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3vH7Kj73hHz9s2G for ; Tue, 7 Feb 2017 00:16:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751592AbdBFNQw (ORCPT ); Mon, 6 Feb 2017 08:16:52 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:51772 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751360AbdBFNQu (ORCPT ); Mon, 6 Feb 2017 08:16:50 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yotamg@mellanox.com) with ESMTPS (AES256-SHA encrypted); 6 Feb 2017 15:16:47 +0200 Received: from dev-r-vrt-156.mtr.labs.mlnx (dev-r-vrt-156.mtr.labs.mlnx [10.212.156.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v16DGlQb001464; Mon, 6 Feb 2017 15:16:47 +0200 From: Yotam Gigi To: netdev@vger.kernel.org, stephen@networkplumber.org, eladr@mellanox.com, idosch@mellanox.com, jiri@mellanox.com, jhs@mojatatu.com, mrv@mojatatu.com Cc: Yotam Gigi Subject: [PATCH net-next/iproute 2/5] tc: bash-completion: Prepare action autocomplete to support several actions Date: Mon, 6 Feb 2017 15:19:21 +0200 Message-Id: <1486387164-40404-3-git-send-email-yotamg@mellanox.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1486387164-40404-1-git-send-email-yotamg@mellanox.com> References: <1486387164-40404-1-git-send-email-yotamg@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The action autocomplete routine (_tc_action_options) currently does not support several actions statements in one tc command line as it uses the _tc_once_attr and _tc_one_from_list. For example, in that case: $ tc filter add dev eth0 handle ffff: u32 [...] \ action sample group 5 rate 12 \ action sample the _tc_once_attr function, when invoked with "group rate" will not suggest those as they already exist on the command line. Fix the function to use the _from variant, thus allowing each action autocomplete start from the action keyword, and not from the beginning of the command line. Signed-off-by: Yotam Gigi --- bash-completion/tc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bash-completion/tc b/bash-completion/tc index 04f969e..c854dc0 100644 --- a/bash-completion/tc +++ b/bash-completion/tc @@ -454,26 +454,28 @@ _tc_filter_options() # Returns 0 is completion should stop after running this function, 1 otherwise. _tc_action_options() { - case $1 in + local from=$1 + local action=${words[from]} + case $action in bpf) _tc_bpf_options return 0 ;; mirred) - _tc_one_of_list 'ingress egress' - _tc_one_of_list 'mirror redirect' - _tc_once_attr 'index dev' + _tc_one_of_list_from $from 'ingress egress' + _tc_one_of_list_from $from 'mirror redirect' + _tc_once_attr_from $from 'index dev' return 0 ;; sample) - _tc_once_attr 'rate' - _tc_once_attr 'trunc' - _tc_once_attr 'group' + _tc_once_attr_from $from 'rate' + _tc_once_attr_from $from 'trunc' + _tc_once_attr_from $from 'group' return 0 ;; gact) - _tc_one_of_list 'reclassify drop continue pass' - _tc_once_attr 'random' + _tc_one_of_list_from $from 'reclassify drop continue pass' + _tc_once_attr_from $from 'random' return 0 ;; esac @@ -715,8 +717,7 @@ _tc() local action acwd ACTION_KIND=' gact mirred bpf sample ' for ((acwd=$subcword; acwd < ${#words[@]}-1; acwd++)); do if [[ $ACTION_KIND =~ ' '${words[acwd]}' ' ]]; then - action=${words[acwd]} - _tc_action_options $action && return 0 + _tc_action_options $acwd && return 0 fi done _tc_one_of_list $ACTION_KIND