Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp162738pxh; Thu, 7 Apr 2022 17:29:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhzU3tC3PEOE6C6GK/huHVhgE85MMU0GqiWze90sF6qFXnJRHDulf7mg4ndwMJ/hRXcu4B X-Received: by 2002:a05:6a00:2442:b0:4fd:8b00:d2f with SMTP id d2-20020a056a00244200b004fd8b000d2fmr16844409pfj.39.1649377791757; Thu, 07 Apr 2022 17:29:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649377791; cv=none; d=google.com; s=arc-20160816; b=iT1eSnRcO+4wNvGA/BbPUqfdkmtEDfjuXfUutD3UI7doZSmD4lxOrO0rEl4Lqe8G/N XDpGZdltKWNly7GKAXfNjd5TqdZ2+Vq90OF3hjpyAzwWBEnIOkV2fthAFlKs2uOiTzrw Ve3npp2yc7bFzWFYepI0gj7J7Sz+TZVBASgGmnwN1jSI4RP+zPbBMBZDN5yCS0lU7cEg +g1OrYz1fvXsxMf5lx0Yx+afQx/TlcYSowyGHwnFiZCEX4G/1Woq3vwZlUx/AQ1LUAAU pKgF7iE59na7BjMG78mccm0r5u1Sq7tzQYGIH1BlkAEzweJh3LiMPsbu8oBy/jEuwkKP 6e6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=zTCuH7DRWeA6y3m792VByCbnJCSD5d8sPofyL9x7kQk=; b=UyA4xEti/HoFupvCqjkGZtxihysAany6+huLeqK13vbmdVcxWd7uriioR/AwAYnTO8 Jqg294RNx16OqCl46lh1DrsqXnlje115xaxlqsFfafysY3QK0Oizm9YcuRta1JqBHxlJ gScovauHFd8G4qXiTI/QFq1hmWa1bUG6KGom8oaqhtgJwDRFzfXUp2EhPafXfDTF93js OshlGc1jGTlyXfMS345UqmJIfzxBKPZ9T+xD8bn6iI91hwyLaSPFx8Gz89snzcTy30NN 0eOsD0o2cKalWHL+A41oUsqH9PWgFyOcPBjdKWjiPrcAW2ISs6zBzhU3qVoLlHu+Q7Jb 409w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jJlMefiw; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id mw1-20020a17090b4d0100b001cb0b433e3dsi3512970pjb.119.2022.04.07.17.29.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 17:29:51 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jJlMefiw; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3C3E34B877; Thu, 7 Apr 2022 16:59:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232626AbiDHABy (ORCPT + 99 others); Thu, 7 Apr 2022 20:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232660AbiDHABx (ORCPT ); Thu, 7 Apr 2022 20:01:53 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A731519A546 for ; Thu, 7 Apr 2022 16:59:52 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id n18so6456877plg.5 for ; Thu, 07 Apr 2022 16:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zTCuH7DRWeA6y3m792VByCbnJCSD5d8sPofyL9x7kQk=; b=jJlMefiwH9XgG6NLbjd89JJtvufWluZRXvvlazq9GvdKI6O6a9lz7943d9lgqklf0N /9ly+qeTAsWGUFEZDzraRV5SUNUohgG07btIL/vpC3RVtCzb6YYFlUOGsYuVj4hiqsTg ij8o4B51z8gse8Hu/aMz/PbhKhQKsfMWQvNBSmy9N7g/91N0ISnsih2CGABcCYfGtd4/ 2G0DRlQc9WbjU/hmRgnGq2Qzv4cTexassnb8jluNUY6SoKou2ZJQhQzSwGCEORJF73pt MFGvCyRj6SrzEBznx+9GH3d4bQM8ST2ArRXVCsxRpBc3fr544iu+SJSl4LCiP6hc4aqx ImOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zTCuH7DRWeA6y3m792VByCbnJCSD5d8sPofyL9x7kQk=; b=hYLax5OmW3y/3UHRQy/5Tiobxh++B9Kqm6URmENL49+ECQ/1/FCbOWn2YMHrcVEOGs N3ivMt4HdrGN1Be0F26uED44HltCzh7QL5vEkzhAbJxFkLV669QcFliupj2NrGz49Ach TP9IfAwjSTOElfNuFiQRwXmrLnRy4dhVzGJVtbKczBaasK978Q6M21xEhGk1I7Xi4rSR 47mlo0lKLxUYX6f3VyeEPWcg+XQIA0QbcR1vMwb6ZZBHiQHQXvXV9KeLAoZjRdVaS+5M CrzH5IZkERte2s4npCNU2FbCldmHxY9Dv3OMZWj///tyUBlpqsQSoWM+ZNx1o0rRrCtt ObbA== X-Gm-Message-State: AOAM530T1Lq5Jr+wZgqylixfaNzLgAkespou+bj75v+BAXUYBCc+fhDU wePB4yX9kdRVimzW15C+ns086y+B6EA= X-Received: by 2002:a17:902:ce04:b0:156:3be:8a7f with SMTP id k4-20020a170902ce0400b0015603be8a7fmr16029825plg.149.1649375991962; Thu, 07 Apr 2022 16:59:51 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bg13-20020a17090b0d8d00b001caa8f51098sm9770532pjb.9.2022.04.07.16.59.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 16:59:51 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] shell: Fix not able to auto complete commands with submenu prefix Date: Thu, 7 Apr 2022 16:59:49 -0700 Message-Id: <20220407235949.2428708-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407235949.2428708-1-luiz.dentz@gmail.com> References: <20220407235949.2428708-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz If the command was given with submenu prefix the code wasn't able to detect the command to be able to generate the auto complete for its arguments. --- src/shared/shell.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/shared/shell.c b/src/shared/shell.c index 72232f7c0..dfda8128a 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -911,6 +911,26 @@ static char **menu_completion(const struct bt_shell_menu_entry *entry, return matches; } +static char **submenu_completion(const char *text, int argc, char *input_cmd) +{ + const struct bt_shell_menu *menu; + char *cmd; + + if (data.main != data.menu) + return NULL; + + cmd = strrchr(input_cmd, '.'); + if (!cmd) + return NULL; + + menu = find_menu(input_cmd, cmd - input_cmd, NULL); + if (!menu) + return NULL; + + return menu_completion(menu->entries, text, argc, + input_cmd + strlen(menu->name) + 1); +} + static char **shell_completion(const char *text, int start, int end) { char **matches = NULL; @@ -928,10 +948,14 @@ static char **shell_completion(const char *text, int start, int end) matches = menu_completion(default_menu, text, w.we_wordc, w.we_wordv[0]); - if (!matches) + if (!matches) { matches = menu_completion(data.menu->entries, text, w.we_wordc, w.we_wordv[0]); + if (!matches) + matches = submenu_completion(text, w.we_wordc, + w.we_wordv[0]); + } wordfree(&w); } else { -- 2.35.1