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

feat(linkli): add spec #2495

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions src/linkli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const openCommandGenerator: Fig.Generator = {
script: ["linkli", "list", "--raw"],
postProcess: function (out, tokens) {
const entered_names = tokens.slice(2, -1);

const split_out = out.split("\n");
if (split_out.length === 1) {
const names = split_out[0].split(",");
const filtered_names = names.filter(
(name) => entered_names.indexOf(name) === -1
);
const suggestions = filtered_names.map((name) => ({
name,
}));
return suggestions;
}
const priority_names = split_out[0].split(",");
const priority_suggestions = priority_names.map((name) => ({
name,
priority: 80,
}));

const remaining_names = split_out[1].split(",");
const remaining_suggestions = remaining_names.map((name) => ({
name,
}));

const combined_suggestions = [
...priority_suggestions,
...remaining_suggestions,
];

const filtered_suggestions = combined_suggestions.filter(
(suggestion) => entered_names.indexOf(suggestion.name) === -1
);

return filtered_suggestions;
},
};

const openSubcommand: Fig.Subcommand = {
name: "open",
description: "Open associated link for a given product",
priority: 75,
args: {
name: "product name",
generators: openCommandGenerator,
},
};

const listSubcommand: Fig.Subcommand = {
name: "list",
description: "List product names found in docbox",
options: [
{
name: "--all",
description: "Show all product names",
},
{
name: "--raw",
description: "Used only for autocomplete suggestions",
hidden: true,
},
],
};

const generateSubcommand: Fig.Subcommand = {
name: "generate",
description: "Generate project-specific linkli collection",
};

const searchSubcommand: Fig.Subcommand = {
name: "search",
description: "Search supported products in linkli",
priority: 60,
};

const completionSpec: Fig.Spec = {
name: "linkli",
description: "Find and open your tech stack links",
subcommands: [
openSubcommand,
generateSubcommand,
listSubcommand,
searchSubcommand,
],
options: [
{
name: ["--help", "-h"],
description: "Show help",
isPersistent: true,
},
{
name: ["--version", "-v"],
description: "Show version",
isPersistent: true,
},
],
};

export default completionSpec;