[OpenAFS-devel] Shell completion: cmd introspection design

Inchara Jayaram incharajayaram2020@gmail.com
Tue, 24 Mar 2026 01:02:00 +0530


--0000000000005ccfeb064db61757
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi,

I=E2=80=99ve been going through the OpenAFS cmd infrastructure, specificall=
y cmd.c
and how command syntax is constructed through cmd_CreateSyntax,
cmd_AddParm, and related helpers.

I have some prior experience working on compiler pipelines and
developer-facing CLI tooling in large C/C++ codebases, so I was trying to
understand how OpenAFS models command structure internally and whether that
can be leveraged directly for shell completions.

>From what I see, cmd_syndesc and cmd_parmdesc already contain most of the
information required (subcommands, parameter types, aliases, hidden flags).
I=E2=80=99ve been experimenting with walking the global syntax list (allSyn=
tax) and
exposing this via a --dump-syntax flag that emits JSON, which can then be
used to generate bash/zsh completions offline.

I had a couple of questions regarding this approach:

Would exposing this through a cmd_Dispatch interception (so that
--dump-syntax bypasses normal argument validation) be acceptable, or would
it be preferable to keep this separate from the dispatch path?
Are there known cases where command behavior is not fully captured by
cmd_syndesc traversal (for example, custom parsing logic, implicit
arguments, or special-case handling) that I should account for?

I=E2=80=99ve also put together a small prototype based on this approach her=
e:
https://github.com/Incharajayaram/openafs/tree/gsoc-dump-syntax

Thanks,
Inchara J

--0000000000005ccfeb064db61757
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi,<br><br>I=E2=80=99ve been going through the OpenAFS cmd=
 infrastructure, specifically cmd.c and how command syntax is constructed t=
hrough cmd_CreateSyntax, cmd_AddParm, and related helpers.<br><br>I have so=
me prior experience working on compiler pipelines and developer-facing CLI =
tooling in large C/C++ codebases, so I was trying to understand how OpenAFS=
 models command structure internally and whether that can be leveraged dire=
ctly for shell completions.<br><br>From what I see, cmd_syndesc and cmd_par=
mdesc already contain most of the information required (subcommands, parame=
ter types, aliases, hidden flags). I=E2=80=99ve been experimenting with wal=
king the global syntax list (allSyntax) and exposing this via a --dump-synt=
ax flag that emits JSON, which can then be used to generate bash/zsh comple=
tions offline.<br><br>I had a couple of questions regarding this approach:<=
br><br>Would exposing this through a cmd_Dispatch interception (so that --d=
ump-syntax bypasses normal argument validation) be acceptable, or would it =
be preferable to keep this separate from the dispatch path?<br>Are there kn=
own cases where command behavior is not fully captured by cmd_syndesc trave=
rsal (for example, custom parsing logic, implicit arguments, or special-cas=
e handling) that I should account for?<br><br>I=E2=80=99ve also put togethe=
r a small prototype based on this approach here:<br><a href=3D"https://gith=
ub.com/Incharajayaram/openafs/tree/gsoc-dump-syntax">https://github.com/Inc=
harajayaram/openafs/tree/gsoc-dump-syntax<br></a><br>Thanks,<br>Inchara J</=
div>

--0000000000005ccfeb064db61757--