Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/withfig/autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
mschrage committed Apr 28, 2021
2 parents 3ccd52c + cb8beb8 commit 989d62b
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions dev/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ export const completionSpec: Fig.Spec = {
},

{
name: "-d, --delete",
name: ["-d", "--delete"],
description:
"All listed refs are deleted from the remote repository. This is the same as prefixing all refs with a colon.",
},
Expand Down Expand Up @@ -2440,7 +2440,7 @@ export const completionSpec: Fig.Spec = {
description:
"Create, list, delete or verify a tag object signed with GPG",
options: [
{ name: ["-l", " --list"], description: "list tag names" },
{ name: ["-l", "--list"], description: "list tag names" },
{
name: "-n",
description: "print <n> lines of each tag message",
Expand Down
4 changes: 2 additions & 2 deletions dev/mask.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// To learn more about FIg's autocomplete standard visit: https://withfig.com/docs/autocomplete/building-a-spec#building-your-first-autocomplete-spec
var executeShellCommand: Fig.ExecuteShellCommandFunction;
// var executeShellCommand: Fig.ExecuteShellCommandFunction;

// The below is a dummy example for git. Make sure to change the file name!
export const completion: Fig.Spec = {
name: "mask",
generateSpec: async (context) => {
generateSpec: async (context, executeShellCommand) => {
// See if use specified a maskfile location

var maskfileLocationIdx = context.indexOf("--maskfile");
Expand Down
2 changes: 1 addition & 1 deletion dev/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const completionSpec: Fig.Spec = {
args: [
{
variadic: true,
template: "filepaths",
template: ["folders", "filepaths"],
},
],
subcommands: [],
Expand Down
2 changes: 1 addition & 1 deletion dev/subl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const completionSpec: Fig.Spec = {
description: "Sublime Text",
args: {
variadic: true,
template: "filepaths",
template: ["folders", "filepaths"],
},
subcommands: [],
};
28 changes: 22 additions & 6 deletions schemas/fig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,22 @@ declare namespace Fig {
*/
loadSpec?: string;
/**
* Dynamically generate a completion spec to be merged in at the same level as the current subcommand. This is useful when a CLI is generated dynamically. This is a function that takes in an array of strings (the tokens the user has typed) and outputs a completion spec object
* Dynamically generate a completion spec to be merged in at the same level as the current subcommand. This is useful when a CLI is generated dynamically.
* This function takes two params:
* 1. Context: an array of strings (the tokens the user has typed)
* 2. executeShellCommand: a function that takes a string as input. It executes this string as a shell command on the user's device from the same current working directory as their terminal. It outputs a text blob. It is also async.
*
* It outputs a completion spec object
*
* @example
* Laravel artisan has its own subcommands but also lets you define your own completion spec.
*/
generateSpec?: Function<string[], Promise<Spec>>;
generateSpec?: (
context: String[],
executeShellCommand: ExecuteShellCommandFunction
) => Promise<Spec>;

// Function<string[], Promise<Spec>>;
}

export interface Option extends BaseSuggestion {
Expand Down Expand Up @@ -330,7 +340,8 @@ declare namespace Fig {
/**
* This function takes one paramater: the output of `script`. You can do whatever processing you want, but you must return an array of Suggestion objects.
*/
postProcess?: Function<string, Suggestion[]>;
postProcess?: (out: string, context: string[]) => Suggestion[];

/**
* Fig performs numerous optimizations to avoid running expensive shell functions many times. For instance, after you type `cd[space]` we load up a list of folders (the suggestions). After you start typing, we instead filter over this list of folders (the filteredSuggestions).
* The suggestions remain the same while the filteredSuggestions change on each input.
Expand Down Expand Up @@ -370,10 +381,12 @@ declare namespace Fig {
*
* It is an async function.
*
* It takes on argument: an array of tokens of what the user has typed
* It takes two arguments:
* 1. Context: an array of tokens of what the user has typed
* 2. executeShellCommand: a function that takes a string as input. It executes this string as a shell command on the user's device from the same current working directory as their terminal. It outputs a text blob. It is also async.
*
* It must return an array of suggestion obejcts.
*
* The function also allows the use of the async function `executeShellCommand` which executes commands from the same current working directory as the user and returns the output as a text blob.
*
* @example
* ```
Expand All @@ -383,7 +396,10 @@ declare namespace Fig {
* }
* ```
*/
custom?: Function<string[], Promise<Suggestion[]>>;
custom?: (
context: String[],
executeShellCommand: ExecuteShellCommandFunction
) => Promise<Suggestion[]>;
/**
* For commands that take a long time to run, Fig gives you the option to cache their response. You can cache the response globally or just by the directory they were run in
* You just need to specify a `ttl` (time to live) for how long the cache will last (this is a number)
Expand Down
4 changes: 2 additions & 2 deletions specs/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ var completionSpec = {
description: "Produce machine-readable output. The output status line for each ref will be tab-separated and sent to stdout instead of stderr.",
},
{
name: "-d, --delete",
name: ["-d", "--delete"],
description: "All listed refs are deleted from the remote repository. This is the same as prefixing all refs with a colon.",
},
{
Expand Down Expand Up @@ -2211,7 +2211,7 @@ var completionSpec = {
name: "tag",
description: "Create, list, delete or verify a tag object signed with GPG",
options: [
{ name: ["-l", " --list"], description: "list tag names" },
{ name: ["-l", "--list"], description: "list tag names" },
{
name: "-n",
description: "print <n> lines of each tag message",
Expand Down
6 changes: 3 additions & 3 deletions specs/mask.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// To learn more about FIg's autocomplete standard visit: https://withfig.com/docs/autocomplete/building-a-spec#building-your-first-autocomplete-spec
// var executeShellCommand: Fig.ExecuteShellCommandFunction;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand Down Expand Up @@ -34,12 +36,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
// To learn more about FIg's autocomplete standard visit: https://withfig.com/docs/autocomplete/building-a-spec#building-your-first-autocomplete-spec
var executeShellCommand;
// The below is a dummy example for git. Make sure to change the file name!
var completionSpec = {
name: "mask",
generateSpec: function (context) { return __awaiter(void 0, void 0, void 0, function () {
generateSpec: function (context, executeShellCommand) { return __awaiter(void 0, void 0, void 0, function () {
var maskfileLocationIdx, out;
return __generator(this, function (_a) {
switch (_a.label) {
Expand Down
2 changes: 1 addition & 1 deletion specs/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var completionSpec = {
args: [
{
variadic: true,
template: "filepaths",
template: ["folders", "filepaths"],
},
],
subcommands: [],
Expand Down
2 changes: 1 addition & 1 deletion specs/subl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var completionSpec = {
description: "Sublime Text",
args: {
variadic: true,
template: "filepaths",
template: ["folders", "filepaths"],
},
subcommands: [],
};
Expand Down

0 comments on commit 989d62b

Please sign in to comment.