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

spec(bundle): Add gem autocomplete and binaries autocomplete #2135

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/_utils/spec.ts
@@ -0,0 +1,7 @@
// eslint-disable-next-line @withfig/fig-linter/no-missing-default-export
export const specToSuggestions = (spec: Fig.Spec): Fig.Suggestion => {
return {
name: spec.name,
...("icon" in spec && { icon: spec.icon }),
};
};
46 changes: 44 additions & 2 deletions src/bundle.ts
@@ -1,3 +1,19 @@
import rails from "./rails";
import rubocop from "./rubocop";
import rspec from "./rspec";
import rake from "./rake";
import { gemsGenerator } from "./gem";
import pry from "./pry";
import { specToSuggestions } from "./_utils/spec";

const EXEC_SUGGESTIONS: Fig.Suggestion[] = [
specToSuggestions(rails),
specToSuggestions(rubocop),
specToSuggestions(rspec),
specToSuggestions(rake),
specToSuggestions(pry),
];

const gemfileGemsGenerator: Fig.Generator = {
script: "bundle list --name-only",
postProcess: (out) => {
Expand Down Expand Up @@ -175,7 +191,30 @@ const completionSpec: Fig.Spec = {
description: "Pass all file descriptors to the new process",
},
],
args: { isCommand: true },
args: {
isCommand: true,
generators: {
script: "bundle list --name-only",
cache: {
cacheByDirectory: true,
strategy: "stale-while-revalidate",
ttl: 60 * 60,
},
postProcess: (out) => {
const gems = out.split("\n");

return EXEC_SUGGESTIONS.filter((spec) => {
if (spec.name === "rspec") {
return gems.includes("rspec-core");
}

return gems.includes(
typeof spec.name === "string" ? spec.name : spec.name[0]
);
});
},
},
},
},
{ name: "config", args: {} },
{ name: "help" },
Expand All @@ -184,7 +223,10 @@ const completionSpec: Fig.Spec = {
{
name: "add",
description: "Add gem to the Gemfile and run bundle install",
args: {},
args: {
name: "gem",
generators: gemsGenerator,
},
options: [
{
name: ["--version", "-v"],
Expand Down
32 changes: 16 additions & 16 deletions src/gem.ts
@@ -1,4 +1,4 @@
const gems: Fig.Generator = {
export const gemsGenerator: Fig.Generator = {
trigger: () => true,
custom: async (tokens, executeShellCommand) => {
const searchTerm = tokens[tokens.length - 1];
Expand Down Expand Up @@ -172,7 +172,7 @@ const completionSpec: Fig.Spec = {
description: "Install a gem into the local repository",
args: {
name: "GEMNAME",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -282,7 +282,7 @@ const completionSpec: Fig.Spec = {
description: "Check a gem repository for added or missing files",
args: {
name: "GEMNAME",
generators: gems,
generators: gemsGenerator,
debounce: true,
isOptional: true,
},
Expand Down Expand Up @@ -345,7 +345,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of gem to cleanup",
generators: gems,
generators: gemsGenerator,
debounce: true,
isOptional: true,
},
Expand Down Expand Up @@ -384,7 +384,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of gem to list contents for",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -533,7 +533,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of gem to download",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -634,7 +634,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of the gem to print information about",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -678,7 +678,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of the gem to print information about",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -708,7 +708,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of the gem to print information about",
generators: gems,
generators: gemsGenerator,
debounce: true,
isOptional: true,
},
Expand All @@ -723,7 +723,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of the gem to print information about",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
requiresSeparator: true,
Expand Down Expand Up @@ -828,7 +828,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Gem to generate documentation for (unless –all)",
generators: gems,
generators: gemsGenerator,
debounce: true,
isOptional: true,
},
Expand Down Expand Up @@ -991,7 +991,7 @@ const completionSpec: Fig.Spec = {
{
name: "GEMFILE",
description: "Name of gem to show the gemspec for",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
{
Expand Down Expand Up @@ -1054,7 +1054,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEMNAME",
description: "Name of gem to unpack",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -1088,7 +1088,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEM",
description: "Name of gem",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -1116,7 +1116,7 @@ const completionSpec: Fig.Spec = {
description: "Uninstall gems from the local repository",
args: {
name: "GEMNAME",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -1297,7 +1297,7 @@ const completionSpec: Fig.Spec = {
description: "Manage gem owners of a gem on the push server",
args: {
name: "GEMNAME",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down
16 changes: 16 additions & 0 deletions src/rspec.ts
@@ -0,0 +1,16 @@
const completionSpec: Fig.Spec = {
name: "rspec",
icon: "https://rspec.info/images/logo.png",
description:
"Behaviour Driven Development for Ruby. Making TDD Productive and Fun",
args: {
name: "file",
description: "The file to run",
default: "./spec",
generators: {
template: ["filepaths", "folders"],
},
},
};

export default completionSpec;
23 changes: 23 additions & 0 deletions src/rubocop.ts
@@ -0,0 +1,23 @@
const completionSpec: Fig.Spec = {
name: "rubocop",
description:
"A Ruby static code analyzer and formatter, based on the community Ruby style guide",
icon: "https://github.com/rubocop/rubocop/blob/master/logo/rubo-logo-symbol.png?raw=true",
Zeko369 marked this conversation as resolved.
Show resolved Hide resolved
args: {
name: "file",
template: "filepaths",
isVariadic: true,
},
options: [
{
name: ["-a", "--autocorrect"],
description: "Autocorrect offenses (only when it's safe)",
},
{
name: ["-A", "--autocorrect-all"],
description: "Autocorrect offenses (safe and unsafe)",
},
],
};

export default completionSpec;