Skip to content

Instantly share code, notes, and snippets.

@jasonappah
Created May 21, 2021 15:57
Show Gist options
  • Save jasonappah/9233a597e82035a8019dbfb424feb452 to your computer and use it in GitHub Desktop.
Save jasonappah/9233a597e82035a8019dbfb424feb452 to your computer and use it in GitHub Desktop.
An attempt at creating a @withfig autocompletion spec taking advantage of Cobra's dynamic completions feature.
// fgh __complete ""
export var completionSpec: Fig.Spec = {
name: "fgh",
description: "Automate the lifecycle and organization of your cloned GitHub repositories"
subcommands: getCmds('fgh complete ""'),
args: getCmds('fgh complete --')
}
const getCmds = (str) => {
let res = []
// execute.text isnt a thing - i was just too lazy to get the actual function to execute a command
const cmds = execute.text(str).split("\n").slice(0,-2)
const cmdsObj = {}
cmds.forEach((cmd) => {
cmdArr = cmd.split("\t")
if (cmdArr.length>1) {
const name = cmdArr[0].strip()
const desc = cmdArr[1].strip()
cmdsObj[name] = desc
}
})
cmdsObj.values.forEach(([cmd, desc]) => {
res.push({"name":cmd, "displayName": desc, args: [
// this is where i gave up and decided it would be easier to do it manually lol
]})
})
return res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment