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 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
7 changes: 7 additions & 0 deletions src/_utils/spec.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 @@ -178,7 +178,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 @@ -288,7 +288,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 @@ -351,7 +351,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 @@ -390,7 +390,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 @@ -539,7 +539,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 @@ -640,7 +640,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 @@ -684,7 +684,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 @@ -714,7 +714,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 @@ -729,7 +729,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 @@ -834,7 +834,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 @@ -997,7 +997,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 @@ -1060,7 +1060,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 @@ -1094,7 +1094,7 @@ const completionSpec: Fig.Spec = {
args: {
name: "GEM",
description: "Name of gem",
generators: gems,
generators: gemsGenerator,
debounce: true,
},
options: [
Expand Down Expand Up @@ -1122,7 +1122,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 @@ -1303,7 +1303,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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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/assets/logo.png?raw=true",
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;