Things to Keep in Mind
When building a completion spec, your aim should be to represent a CLI tool in Fig's completion spec standard as best you can.
If a completion spec misrepresents a CLI, Fig won't just offer incorrect suggestions, but may even block the user from executing a command, or worse, cause the user to execute a command they didn't mean to! Fortunately, keeping the following in mind will help you avoid this:
Subcommands & Options
- Make sure the
nameprop exactly matches the token the user would type.- Don't include
=or the arg. i.e. usename: ["-m"]notname: ["-m=message"] - Don't include a friendly message. i.e. use
name: "commit"notname: "make a commit 😊"
- Don't include
- Subcommands can nest beneath other subcommands (e.g.
aws s3 cp) - Options cannot nest beneath options.
Arguments
- If a subcommand or option takes an argument(s), you must signal this to our parser by at least including an empty Arg object (e.g.
args: {}). - If a subcommand or option does not take an argument, you should NOT include an Arg object
- If an argument is optional, it should use the
isOptional: trueprop - If an argument is variadic (can repeat infinitely), it should use the
isVariadic: trueprop
What happens if you don't include an arg object?
Let's imagine you forgot to say that -m takes an argument in the completion spec for git commit -m <msg>.
- If a user typed:
git commit -m[space], Fig would suggest other options NOT enforce that amsgshould be input - If a user typed:
git commit -m "my message"[space], Fig would think there is an error and therefore hide, rather than suggesting other options.- Why would Fig hide? Because we didn't know
-mtook an argument, we assumed"my message"was a subcommand or an option nested beneathcommit. Fig assumes the completion spec is correct. And because the completion spec doesn't specify an option or subcommand called"my message", we assume the user is wrong. And when we think the user is wrong, we hide!
- Why would Fig hide? Because we didn't know
Next
You're now ready to build your own Completion Specs!
- Build specs for private CLIs and scripts
- Learn more about the completion spec standard
- Contribute to our public specs
- Join Fig's community Discord