Description
Refactor completion script generation to use ToolInfoV0 for all 3 supported shells: bash, fish &
zsh.
@rauhul previously submitted PR #695 that refactored bash. He graciously sidelined his PR to
allow me to merge my numerous pending completion improvements, which have now all been
merged.
My WIP draft PR refactors all 3 shells to use ToolInfoV0, except it has 3 issues that I think require ToolInfoV0
to be updated:
- ToolInfoV0 must include
parsingStrategy
inArgumentInfoV0
(needed for zsh). - The
HelpCommand
that is injected into ToolInfoV0 has a--version
flag, but it is not seen
by the completion code. Might be useful to try to resolve all issues from Problems with auto-created--help
flag,-h
flag, &help
subcommand in generated completion scripts & help output #671, too. - Nonexclusive flags implemented via an array of enum cases are represented as different names
for the sameArgumentInfoV0
, but each case should have its ownArgumentInfoV0
. If such
enum cases can have multiple names each, then all names for a single case should be in the
sameArgumentInfoV0
. Example enum & property (fromCompletionScriptTests.swift
):enum Kind: String, ExpressibleByArgument, EnumerableFlag { case one, two case three = "custom-three" } @Flag var allowedKinds: [Kind] = []
Bonus issue: the following seems similarly inconsistent in all of SAP that I've seen, not just
in ToolInfoV0. case three = "custom-three"
from above is considered as --three
for a flag
from allowedKinds
, but as custom-three
as an option value for --kind
from
@Option() var kind: Kind
. This is the case in the original completion scripts, in ToolInfoV0
& even in SAP's command-line argument verification. It seems to me that it should be consistent
throughout; of the 2 options, custom-three
seems more sensible.
ToolInfoV0 and/or SAP might have other issues, but I haven't isolated them.
Note that my PR for this no longer replaces -
with _
in bash shell function names because:
- it's unnecessary (
-
is supported in function names;-
is not supported only in variable names) - bash is now consistent with the other 2 shells, and can use the same Swift code to generate function names
- it avoids (albeit exceedingly unlikely) potential name clashes between, e.g., subcommands named
a-b
&a_b
I can split it out into a separate PR, if necessary…