Skip to content

Commit

Permalink
feat: add mix completion spec (withfig#501)
Browse files Browse the repository at this point in the history
* feat: add mix completion spec

* fix: remove unneccessary replace

* feat: reduce cache time and hide options by default

* fix: remove
Usage: mix [task]

Examples:

    mix             - Invokes the default task (mix run) in a project
    mix new PATH    - Creates a new Elixir project at the given path
    mix help        - Lists all available tasks
    mix help TASK   - Prints documentation for a given task

The --help and --version options can be given instead of a task for usage and versioning information. from suggestions

* chore: revert package-lock.json

* add generators

* revert unintended changes
  • Loading branch information
benvp authored Aug 29, 2021
1 parent 608771c commit ef98a2d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
11 changes: 10 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@
"contributions": [
"code"
]
},
{
"login": "benvp",
"name": "Benjamin von Polheim",
"avatar_url": "https://avatars.githubusercontent.com/u/981344?v=4",
"profile": "https://github.com/benvp",
"contributions": [
"code"
]
}
]
}
}
35 changes: 33 additions & 2 deletions dev/mix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ const completionSpec: Fig.Spec = {
],
},
{
name: "pp",
name: "help",
description:
"Prints documentation for a given task (Lists all the tasks if no task is specified)",
args: {
isOptional: true,
name: "task",
isOptional: true,
description: "Prints documentation for a given task",
generators: {
cache: { ttl: 10000 },
script: "mix help",
postProcess: makeTaskSuggestions,
},
},
options: [
{
Expand All @@ -70,6 +76,17 @@ const completionSpec: Fig.Spec = {
],
},
],
args: {
name: "task",
description: "Invokes the task (mix run) in a project",
isOptional: true,
generators: {
cache: { ttl: 10000 },
script: "mix help",
postProcess: makeTaskSuggestions,
},
},

options: [
{
name: ["-h", "--help"],
Expand All @@ -82,4 +99,18 @@ const completionSpec: Fig.Spec = {
],
};

function makeTaskSuggestions(out: string) {
return out
.split("\n")
.map((task) => {
const [name, description] = task.split("#").map((x) => x.trim());

return {
name: name.replace(/^mix /, ""),
description,
};
}) // filter out commands which do not make sense here
.filter((x) => !["mix", "help", "new", "iex -S mix"].includes(x.name));
}

export default completionSpec;

0 comments on commit ef98a2d

Please sign in to comment.