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 086ED43188; Tue, 17 Oct 2023 09:11:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CF08C40285; Tue, 17 Oct 2023 09:11:07 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 0D8ED40279 for ; Tue, 17 Oct 2023 09:11:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697526666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MXexp0Bn2Hp15SQNMyhHVw0YtPmY3ofCvhCc+NLbfTc=; b=cUJyPlH7P0tdUq5chXV/E9bjgJN0wp7KEHaufdYIBumxc9sk7eJwr7b2rEI65yRzf4N5mL M4SGguh+p8kkil7UqsFhrnTqc8gvxXN6rGdXxbKCrIYteBcxpUr/JJw5ruNIPqKWVOM7st NDasu6+Z0p06jc6nIGg0seFZztcjauU= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-361-XNJ_-qSxPriX8lRU5PUo3A-1; Tue, 17 Oct 2023 03:11:04 -0400 X-MC-Unique: XNJ_-qSxPriX8lRU5PUo3A-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2c50d73e212so29845211fa.1 for ; Tue, 17 Oct 2023 00:11:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697526663; x=1698131463; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MXexp0Bn2Hp15SQNMyhHVw0YtPmY3ofCvhCc+NLbfTc=; b=JASi2K+0PpMj17+YXLIE5/jA4AQR5LxV9N9WgrR4s51DmBVsgEyxug7TkAQQ46vEW8 tKDVz6Wy6j/EnqTH2VKh5qvmvruy5uzcKfGBGB4aM5z16xwBNV0K5lSkuZBgtbBTcAYj LMWnHZWLOBAAxtltRFupxJyy3bsLhdRg0T38nWMlorSwXBFrbKoyXeXxIQfmAMCsAF/P lDWQroLXiPistjFElx+uxb4Al1ngoVywf9cPvE6t79tLdub/3dAoRj8vFsmzJirugI92 n9KpDm8gVEzh39CL0i4AOWR4krw3+xub06xAPv/+Kyo/Ihs2Jl3prhHhd1In8eMP4jol GbWQ== X-Gm-Message-State: AOJu0Yw1pJhpZ+RcJFu4CLQs4g9+XS7xyuWGuv86xrFXFYY6m03qNcHf 0vkmyb+x/HpitSZ6TPNpXzGTYj0Eo82rq5FH/n2iBL6q+b3QyOXM2TsUbUP9Pu2bydUNAuzq0NJ RIP/TGxNE7V4jD6cbFxo= X-Received: by 2002:a2e:94d0:0:b0:2c5:994:ed72 with SMTP id r16-20020a2e94d0000000b002c50994ed72mr1069573ljh.21.1697526663122; Tue, 17 Oct 2023 00:11:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWMzV+9NXuW7DtLiBh/PwFTobvOXyx38w0Xp+o8nU+01QFnSinZiiKWMLRauM2rrguEIXIM7m5Q41QPliaVww= X-Received: by 2002:a2e:94d0:0:b0:2c5:994:ed72 with SMTP id r16-20020a2e94d0000000b002c50994ed72mr1069562ljh.21.1697526662820; Tue, 17 Oct 2023 00:11:02 -0700 (PDT) MIME-Version: 1.0 References: <20230802170052.955323-1-bruce.richardson@intel.com> <20231016140612.664853-1-bruce.richardson@intel.com> In-Reply-To: <20231016140612.664853-1-bruce.richardson@intel.com> From: David Marchand Date: Tue, 17 Oct 2023 09:10:51 +0200 Message-ID: Subject: Re: [PATCH v4 0/7] document and simplify use of cmdline To: Bruce Richardson Cc: dev@dpdk.org, rjarry@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Hi Bruce, On Mon, Oct 16, 2023 at 4:06=E2=80=AFPM 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. - 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 =3D [] + prefix, sep, cmd_name =3D tokens[0].partition(':') + if cmd_name: + tokens[0] =3D cmd_name + else: + prefix =3D 'cmd' + if tokens[0].startswith('<'): print('Error: each command must start with at least one literal string', file=3Dsys.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 - 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.p= y 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 =3D t[1:].split('>') - t_val =3D 'NULL' + if len(t_type.split('(')) =3D=3D 2: + t_type, t_val =3D t_type.split('(') + t_val =3D '"' + t_val.split(')')[0] + '"' + else: + t_val =3D 'NULL' else: t_type =3D 'STRING' t_name =3D t @@ -113,7 +117,7 @@ def process_commands(infile, hfile, cfile, ctxname): continue if '#' not in line: line =3D line + '#' # ensure split always works, even if no help text - tokens, comment =3D line.split('#', 1) + tokens, comment =3D line.rsplit('#', 1) instances.append(process_command(tokens.strip().split(), cfile, comment.strip())) print(f'static __rte_used cmdline_parse_ctx_t {ctxname}[] =3D {{') Which translates as: cmd_brief:help # help: Show help help section # help: Show help > > The "cmdline" example itself, is not converted over, as it should > probably remain as a simple example of direct library use without the > script. +1 --=20 David Marchand