Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: complex command and subcommand descriptions and completions. #77

Merged
merged 48 commits into from
Jan 28, 2022

Conversation

davidovich
Copy link
Owner

@davidovich davidovich commented Jan 20, 2022

This has been cooking for a long time.

This long commit series introduces a way to describe complex sub-commands to taylor declarative command line interfaces to a proxied command. Not very useful when targeting an installed command, but very powerful when targeting docker containers.

It essentially allows tailoring a command-line to a container, which is typically hard to invoke (volume mounts, environment settings, image repository name, etc). Supports help, completions and flags.

This change also leverages cobra's dynamic completions. This allows delegating completion to a program inside the container. I use it to give a better cli to a makefile program (a series of utility makefile targets) which typically has poor user oriented command line UX.

closes #67

can parse config file with exec:invoker where invoker can be a complex
type describing help, args, completion and sub-args

keeps compatibility with simple slice args case
Makes the config a private member as it is now accessed only from the
summon package.

We normalize earlier the invokers and handles. Because handles are
unique, we make a global map of them, derived from the config. We now
use these normalized structs throughout. This removes CmdSpec computing
duplication.

This also allows failing fast if duplicated handle are detected.
Boxes were a packr concept, this commit removes the remnants of the box
name.
This allows failling fast (faster than at command execution).

We cannot recover from a badly formed config file so might as well fail
as soon as we can.
Invoker is more of an execution environment where you start processes.

And CmdArgs is really the Cmd and args.
This was the early version of the now more relevant CmdSpec. Everything
we need to invoke a target is now in the CmdSpec.

Removed environment exec support as this did not make sense in container
contexts. Templates can be used to vary environment in the
ExecEnvironment.
flags to be rendered cannot be stored in a map as iteration is
non-deterministic.

Also, return userValue when the flag is evaluated.
Otherwize this will introduce empty args when invoking the command.

Allow for empty args if the result is an empty array.
This is part of the interface to summon. Every call to completion must
yield a '\n' separated completion string. If the underlying call cannot
generate that, you can template your way with a join "\n" $result.
Global flags (at invoker level) are marked global, others are marked
local to the command.
Handles are executed in a specified execution environment.
When subcmds have arg hints (subcmd [hint]) it is not findable by the
subcmd (args) map. Use prefix to allow user to use hint as this is
practical in reflected help.
What we are combining is actually args, not a cmd. And we are specifying
a subCmd not args.

This is of course a breaking change, but included in the config change
that is breaking anyhow.
Before this change, SubCmds could not use ArgSliceSpec and this was
confusing. The solution is to generalize the config part and normalize
to a CmdSpec and FlagSpec, recursively.
@davidovich davidovich merged commit 4ee65e0 into main Jan 28, 2022
@davidovich davidovich deleted the implement-better-parser branch January 28, 2022 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: support dynamic completions and delegation
1 participant