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(sake): create spec #2459

Closed
wants to merge 3 commits into from
Closed
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
124 changes: 124 additions & 0 deletions src/sake.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
const commonOptions: Fig.Option[] = [
{
name: ["--config-path", "-c"],
description: "Specify the path to the configuration file",
isPersistent: true,
},
{
name: ["--sake-app-path", "-s"],
description: "Specify the path for the SakeApp package",
isPersistent: true,
},
];
const commonCommandSpecificOptions: Fig.Option[] = [
{
name: "--case-converting-strategy",
description: "Specify the strategy for converting command names' case",
args: {
name: "strategy",
default: "keepOriginal",
suggestions: ["keepOriginal", "toSnakeCase", "toKebabCase"],
},
priority: 55,
},
];

const completionSpec: Fig.Spec = {
name: "sake",
description:
"🍶 Swift-based utility for managing command execution with dependencies and conditions, inspired by Make",
generateSpec: async (_tokens, executeShellCommand) => {
const { stdout } = await executeShellCommand({
command: "sake",
args: ["list", "--json"],
});
const commands = JSON.parse(stdout);
const subcommands = Object.keys(commands.groups).reduce(
(acc, groupName) => {
const group = commands.groups[groupName];
return [
...acc,
...group.map((command) => {
return {
name: command.name,
description: command.description || "The command to run",
priority: 76,
icon: "🍶",
options: [...commonOptions, ...commonCommandSpecificOptions],
};
}),
];
},
[]
);
return {
name: "sake",
subcommands,
};
},
subcommands: [
{
name: "init",
description:
"Initialize a new SakeApp project template for defining commands",
options: [...commonOptions],
},
{
name: "clean",
description:
"Remove all build artifacts generated by the SakeApp to ensure a clean state for future builds",
options: [...commonOptions],
},
{
name: "list",
description: "List all available commands defined in the SakeApp",
options: [
...commonOptions,
...commonCommandSpecificOptions,
{
name: ["--json", "-j"],
description: "Output the list of commands in JSON format",
priority: 45,
},
],
},
{
name: "run",
description: "Run the specified command from the SakeApp",
args: {
name: "command",
description: "The command to run",
generators: {
script: ["sake", "list", "--json"],
postProcess: (output) => {
const commands = JSON.parse(output);
return Object.keys(commands.groups).reduce((acc, groupName) => {
const group = commands.groups[groupName];
return [
...acc,
...group.map((command) => {
return {
name: command.name,
description: command.description,
priority: 76,
icon: "🍶",
};
}),
];
}, []);
},
},
},
options: [...commonOptions, ...commonCommandSpecificOptions],
},
],
options: [
{
name: ["--help", "-h"],
description: "Show help information",
isPersistent: true,
priority: 40,
},
],
};
export default completionSpec;