โ๏ธ
Building products for startups at AngelList
๐ SF
๐จ๐ฆ Toronto originally
Cobra command to generate a Fig autocomplete spec
There are two automatically generated help utilities in Cobra. One is a subcommand "help" on the root command, and the other is a --help flag that exists on every command.
The default help command works by using zero or more subcommands, and adding the term help
after the root command. For example, usage looks like pulumi help
, pulumi help config
, or pulumi help config cp
. This is unique behaviour and can be customized.
The help flag is different. It is automatically set by cobra behind the scenes. However, this can be customized as well.
Adding these pieces should be rather straightforward, but some research is required to understand how the customizations work.
This may not be an issue. After all, adding packages in node updates the lock files. Just need to confirm whether or not it matters that some versions in go.sum are being updated.
Should be able to set using this
I believe we should be able to generate the args for commands by using the Command.Use and Command.ValidArgs provided for shell completions.
Cobra shell completions: https://github.com/spf13/cobra/blob/master/shell_completions.md
Bash completion reference: https://github.com/scop/bash-completion
What do we think about prioritizing local options over inherited options?
Pass in your own command name and arg generator function. Both optional.
Accessing .Hidden
on Cobra's built in completion
command returns false, even though it's clearly defined as hidden.
Because of this, the completion
command is being included in the generated fig spec. Can always just check for the name 'completion', but this is a bit hacky (what if the CLI provides it's own completion command that is not hidden).
Should be able to add folder and filepaths templates to args using https://github.com/spf13/cobra/blob/4fd30b69ee2b62cf3bbecf0a423f8a1ee47f5f24/shell_completions.go#L54 and https://github.com/spf13/cobra/blob/4fd30b69ee2b62cf3bbecf0a423f8a1ee47f5f24/shell_completions.go#L83
I have chosen Pulumi as my sandbox for testing this command. They use a customized version of the built in shell completion command, and rename it from completion
to gen-completion
. For some reason, genFigSpec's spec has the subcommand completion
, but not gen-completion
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.