From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 229CB4318A; Tue, 17 Oct 2023 10:29:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 950C840279; Tue, 17 Oct 2023 10:29:54 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id A417140269 for ; Tue, 17 Oct 2023 10:29:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697531392; x=1729067392; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=tyYy54utaHq0k60QxvykSbgUIbincgUd5mTEwSPPHZg=; b=E7gJHWfwYWbgeogUDtORfW5id6YCiip7DQwvb9hToZjYBU08lEa08aBR FG1Qz/8sxd9KthqKGhgNoMMNN5lD1NlU1nzo4TVXwLi9p5RH0VMjkmZjC hXbjjh0Mc+2Xd93kq63e3tAscepDluoQ5EjbUsXwboZEtT1CPxJfaZ8L6 WBcxRv9iKPQK5DH8VL76B+FOLuuoZa/MvQnuyigIU8QJLjC5GDFeMuvII HgRNehUWDcwvmJ0u/qn7WMUFDA7KnSe71jkliWgbhJQXCfrIzQCgfkXo/ hOcQnQTuBcEQ/2wHBOReiwNfdcbGrB/7+8gzfgaQkMU7Vnup4qwum2ONJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="365083357" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="365083357" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2023 01:29:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="791163747" X-IronPort-AV: E=Sophos;i="6.03,231,1694761200"; d="scan'208";a="791163747" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga001.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 17 Oct 2023 01:29:42 -0700 Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Tue, 17 Oct 2023 01:29:41 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32 via Frontend Transport; Tue, 17 Oct 2023 01:29:41 -0700 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.41) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.32; Tue, 17 Oct 2023 01:29:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jSbm47BDDfQ/jzLmh1a8bU1+7IFSTUbtgmYJSGOE3piDxNmjdmxBQYq7mnVB8tdtZThfI3cLUsMKSY0GDsceP0PmUK0SF8KSYv41e8j/aU8FwEbNKcV2rLydhV1Y3MR/X+U6c+qP0PowHII0fTthArp0MsKrz6EkQRvTmC6IYUC6iLnIAxiwlRebi940QOaFvuFUfa7COrQfJFLDJHQWJANwyBAFp5STquf0/J+oQH6HEs+E/FvYedWCpUn5SxD8weUEMAiBcFzjOzYLqWJt2WZbZCImeO1ALeH4oihx5a2dDlzCK0uAQofmHj6Zpcg5R2jQX5X+ZivyzxGTN7zQ/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9mpgHuCwHiJ9DAZiUnXymm0k30X9+WGL7eOi2FOdlrE=; b=Vh7Qok3FZSRB7DIh6gbIG4ZXNAszACuOKgE7bPHMKwcpXS11hiG+Kaf+2DRzIF33hgiEXN1Cp9w+cFE7ixg7gx+iPsgQPDl6ts2qX9hev8sznYOKKCN1Vxoi4zaVNT7VOjzsgWmP8/CXg9XcsN5XdrFHNnYGvHIonJyGZhBIcA9/rj2EGm79SlkhBJTZaFEsKr9N3nw41hjeWIHqOi8z3g00rTm08mCeKJsf5y0KpM/GxZuwWyG/Gvx6sUqErhkTpZBuOcTRTXqbVwBYGZAvZMOx+cK9fmXWZoB1IyqIlC9ozZPXe58XXExx8QlPs+qVFc5mYsnIl2XSfofkhQhlZg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) by CH3PR11MB7938.namprd11.prod.outlook.com (2603:10b6:610:12f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Tue, 17 Oct 2023 08:29:39 +0000 Received: from DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::68fb:c3f4:75e7:5fb5]) by DS0PR11MB7309.namprd11.prod.outlook.com ([fe80::68fb:c3f4:75e7:5fb5%4]) with mapi id 15.20.6886.034; Tue, 17 Oct 2023 08:29:39 +0000 Date: Tue, 17 Oct 2023 09:29:34 +0100 From: Bruce Richardson To: David Marchand CC: , Subject: Re: [PATCH v4 0/7] document and simplify use of cmdline Message-ID: References: <20230802170052.955323-1-bruce.richardson@intel.com> <20231016140612.664853-1-bruce.richardson@intel.com> Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: DUZPR01CA0161.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bd::18) To DS0PR11MB7309.namprd11.prod.outlook.com (2603:10b6:8:13e::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7309:EE_|CH3PR11MB7938:EE_ X-MS-Office365-Filtering-Correlation-Id: 619f654f-44b6-499e-6c6b-08dbceeb3405 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cpkKKMZxnd+eWbuUSjSgIQHseSGJwnYpmOiurcYxR3eSkjQHFX0B35zqHilykL3aYXmQH91eHWpFe2C4M4oVRyWwwKROWL0dET9E336wvLRTvxz/eYUmyEcEuomQMG4I5Zq25HDwW4kH303OSoeqXlQijT/ozRkhWtgvIny1Y73e9Ff5yZb6hC6p3QuxRqENzHuJGwMZof3DZe8Gwhhk6lflqtrI6erZm2+68DYVci3KXt7PlF/iOFsSehziEo0xgX61O2u5UUe+uLWj+wkdwGcFg+sDnlUmninAMDwKMPMMA0WQxM7TrVmKYVmxZyyP+rKXA+qaRWclhCrKh6duUxNopae/ylHRmAPPB9wVwbJcpTH01UCkQfSDR5WbmsyHpoKzasOwk8zEBykWNtJllIIunXOdZhCw8w0y5IAh4mZQtCRlrqQMqKqsFRQ7dm/rgDkWLVAgK78dVuHoAViBZn+RDlZGsWNomHd2a3/nl0+yqIEpbuAv+/V1oZefbQPFsVi0CzJ8HyShBx6Hm24IbHOdbkuWnl8Qus0MUHTgWGtvdPEqMiUL84e1bNxbXB5L X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7309.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(376002)(396003)(39860400002)(136003)(366004)(346002)(230922051799003)(186009)(64100799003)(1800799009)(451199024)(83380400001)(53546011)(26005)(5660300002)(4326008)(8936002)(8676002)(44832011)(86362001)(41300700001)(82960400001)(66899024)(6486002)(2906002)(478600001)(66476007)(66946007)(316002)(66556008)(6916009)(6666004)(6506007)(6512007)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?dSt4SHJCeHJHSTNjNGdoMGxPM0dBcGdtbVlpellCa2hzMktnRTZzMVRxeWUv?= =?utf-8?B?RVR5bjNEc0tyRG9BQ1U4K1Z2akkwOXJrbitSSXJLcWFqT1FpK3Bwemh6QXR0?= =?utf-8?B?L0tVblQrSzNVUzlsTjhRR040ckNtbTJSVHBNNSsrRVBWN1p2b0F4dFRNNWJi?= =?utf-8?B?ajFUQTFYdm53bkx2UDlhS05scDVKSVJqdmxSRlJYN0dNZm1kZnpSL3ZYUXpu?= =?utf-8?B?cVh1L1R1bjdGNDRkVU84WU1vYlNSK2ljRFZWZ21iTDlGbHBDYWtReldQdGFw?= =?utf-8?B?MnEzRUNVdmpHQW5zTS9nSFJ4bzZCdDhpa3k5WHNaUE9vNk9Mdm5qbmFrdDRY?= =?utf-8?B?NFBaYjFHYzZZWXB4ZG1mSCtoZWlmN2NCMlIwaFFtVXlvUkFYMDVzaGNETjFB?= =?utf-8?B?ZzNqNGtVcjZycTNlL2ZkNzBsYnFPdXN0QjNJZ2lqR3RhbVdNYU9RTFBPQ1U4?= =?utf-8?B?czNGVTFUTGpndVd6ZTNyUnhPUVNoSm1SMnlONTkweHRwU3ZKSWU1dmhvcVVm?= =?utf-8?B?eUNIOElQMXBhNFVoaW41dHU0WlFKZG9KWFk1aDVNZ29MS1RsS0pZYUtZVDlk?= =?utf-8?B?WWtRUFVvdVdwOXN4OTZaeVRxSlZ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YXVFMmhFSDNLYkZWWkNnTmlNUW1QUnh6UWhtK1I2c1JRUGM4SDh6?= =?utf-8?B?NmZpWU9UcmtFajg5ZXhNanJUbUwxUWZvbERrcHczcnB4SXQyb3RKSUpBWXZa?= =?utf-8?B?cTFpaXczVS9yMXZiQThuQzhkaENDd3ptdmtNQVJsV2Y2NU5jeWp3WHhUbnp0?= =?utf-8?B?c3dCKy9HQW5rNUFZMWdaanVsYzQvMDRSWHJkemdpY2w5YTRtbHFja1RENTUw?= =?utf-8?B?TGhlOUQ2dTdmOUtka0ttZzU2R2kvQmdqNndQNzVvZk50Tyt1YVFJQTFvV3BI?= =?utf-8?B?aTVGeGJIZ2xPSWdEM1M0ZFI4RUFTVXNId21WVEp0ZEhzQncrOEJjV0dEUU43?= =?utf-8?B?QndZQ1E0ZU4xRjZaYWt1Umw1UnJvK0s5R2V5cU5yQ1FVUnhEalQ4Y0VBcUdn?= =?utf-8?B?Mk41NWFpQldxdmE3U1hBS1JNYjZSQmxMbm1mTFkrbUoxa0NwbU5CdE5ONFdw?= =?utf-8?B?bm1aYjNnMk02NFpFSGp4Z0Q5RjlqNlZRYU9qWk5VU080aUY3OEJWd2xZaGhS?= =?utf-8?B?UHkxbmY2Sm8xaC9BSFZCQzdESmdBWmpGVmxNNXB5cHVpME1IQ3IzdVhYeGMw?= =?utf-8?B?d2lBeWJELzBCVVdRNGZTbXFtTytMNG1ka09vM2E3MHB4Rm5WNlFQblVGRWJv?= =?utf-8?B?cWc9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: 619f654f-44b6-499e-6c6b-08dbceeb3405 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7309.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2023 08:29:39.0615 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QoznwEuukPa+Bjj9RIX2fnOBU3VZHAFslz4HrXTX1J/irhHCL8eY3yB9JdQfd4AwWZiBrDi32ddYbaOGRIbMLd8/vcTbsajbu0xM7p+ye2o= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR11MB7938 X-OriginatorOrg: intel.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Tue, Oct 17, 2023 at 09:10:51AM +0200, David Marchand wrote: > Hi Bruce, > > On Mon, Oct 16, 2023 at 4:06 PM Bruce Richardson > wrote: > > > > The DPDK commandline library is widely used by apps and examples within > > DPDK, but it is not documented in our programmers guide and it requires > > a lot of boilerplate code definitions in order to used. We can improve > > this situation by creating a simple python script to automatically > > generate the boilerplate from a list of commands. > > > > This patchset contains a new documentation chapter on cmdline library, > > going through step-by-step how to add commands and create the necessary > > token lists and parse contexts. > > > > Following that initial doc patch, the set then contains a > > boilerplate-generating script, as well as a set of four patches showing > > its use, by converting four examples to use the script instead of > > having the hard-coded boilerplate. Once the script is used, adding a new > > command becomes as simple as adding the desired command to the .list > > file, and then writing the required function which will be called for > > that command. No other boilerplate coding is necessary. > > > > Script obviously does not cover the full range of capabilities of the > > commandline lib, but does cover the most used parts. The code-saving to > > each of the examples by auto-generating the boilerplate is significant, > > and probably more examples with commandlines can be converted over in > > future. > > This is not something blocking for the series, but I had a quick try > with testpmd to see where this series stands. > I hit, right off the bat, some of those limitations, but I think there > are not that difficult to deal with. > Thanks for investigating. Item #2 below is something I'd already been thinking of, but had not yet implemented. The hope was to get the basics in first and iterate thereafter, rather than trying to get it all in in one go. However, if I have the chance, and depending on how long before this set gets merged, I might have a try at a respin with an additional feature. > > - testpmd accepts both "help" and "help
" commands. > But the cmdline library does not provide a way (afair) for specifiying > this "optional" aspect. > > And it can't be expressed with this series current syntax since > generated symbols would conflict if we ask for two "help" commands. > > My quick hack was to introduce a way to select the prefix of the > generated symbols. > There may be a better way, like finding a better discriminant for > naming symbols... > But, on the other hand, the symbols prefix might be something a > developer wants to control (instead of currently hardcoded cmd_ > prefix). > > @@ -20,6 +20,12 @@ def process_command(tokens, cfile, comment): > """Generate the structures and definitions for a single command.""" > name = [] > > + prefix, sep, cmd_name = tokens[0].partition(':') > + if cmd_name: > + tokens[0] = cmd_name > + else: > + prefix = 'cmd' > + > if tokens[0].startswith('<'): > print('Error: each command must start with at least one > literal string', file=sys.stderr) > sys.exit(1) > > (etc... I am not copying the rest of the diff) > > I then used as: > > cmd_brief:help # help: Show help > help section # help: Show help > Interesting. I actually had no plans to even consider moving something like testpmd over. However, this is an interesting one, though I'm not really sure I like it that much as a feature :-) I rather like having unique prefixes for each command. I wasn't actually aware of the testpmd "help
" command at all. I will have to look into it. > > - Multi choice fixed strings is something that is often used in > testpmd, like here, in the help
command. > Here is my quick hack: > > diff --git a/buildtools/dpdk-cmdline-gen.py b/buildtools/dpdk-cmdline-gen.py > index 3b41fb0493..e8c9e079de 100755 > --- a/buildtools/dpdk-cmdline-gen.py > +++ b/buildtools/dpdk-cmdline-gen.py > @@ -35,7 +35,11 @@ def process_command(tokens, cfile, comment): > for t in tokens: > if t.startswith('<'): > t_type, t_name = t[1:].split('>') > - t_val = 'NULL' > + if len(t_type.split('(')) == 2: > + t_type, t_val = t_type.split('(') > + t_val = '"' + t_val.split(')')[0] + '"' > + else: > + t_val = 'NULL' > else: > t_type = 'STRING' > t_name = t > @@ -113,7 +117,7 @@ def process_commands(infile, hfile, cfile, ctxname): > continue > if '#' not in line: > line = line + '#' # ensure split always works, even if > no help text > - tokens, comment = line.split('#', 1) > + tokens, comment = line.rsplit('#', 1) > instances.append(process_command(tokens.strip().split(), > cfile, comment.strip())) > > print(f'static __rte_used cmdline_parse_ctx_t {ctxname}[] = {{') > > > Which translates as: > cmd_brief:help # help: Show help > help section # help: Show help > +1 I was actualy thinking that adding support for multi-choice fixed strings is something we should add. One thought that I had was that "#" is not a particularly good choice of separator here. While, as you show, it can be made to work; I think - since we are defining our own syntax here - that it would be both simpler for the script, and simpler for the user, to have "|" as the option separator. It should be familiar for everyone as an option separator from regexes, unlike "#" which is more familar for comments. So what about: help <|all|control|display|config|ports|>section By starting with the separator, we should avoid having to provide the STRING type at all. To my previous point on not liking to have a prefix-specifier, the alternative to making testpmd work with the script is to tweak very slightly the "help
". help # show general help help on <|all|control|display|config|ports|>section By making the command "help on ports" rather than "help ports" we would avoid the need for the prefix syntax. WDYT? /Bruce