-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to list available tasks (#3)
* Add command to list available tasks * Update license from ISC to MIT * Add moonx autocomplete support * Reorder bin commands in package.json * Update version number in package.json * Add stdout.end() to fix CLI output * Remove unnecessary usage of command in index.ts * Add error handling for invalid commands in CLI * Fix for-in loop in index.ts * Fix for-of loop in CLI commands iteration * Remove console.log statement in index.ts * Add options and version to CLI * Remove console logs and update Fig.Generator in fig.ts * Fix workspace filtering in list function * Remove pnpm setup from check.yml workflow
- Loading branch information
Showing
9 changed files
with
104 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const generator: Fig.Generator = { | ||
script(args) { | ||
return [ | ||
"moonx", | ||
"_moonx_list", | ||
...args.filter( | ||
(arg) => !arg.startsWith("-") && arg.length && "moonx" !== arg, | ||
), | ||
]; | ||
}, | ||
trigger: "moonx", | ||
postProcess(out) { | ||
const lines = out.split("\n"); | ||
return lines.map((line) => { | ||
return { | ||
name: line, | ||
}; | ||
}); | ||
}, | ||
}; | ||
|
||
const completionSpec: Fig.Spec = { | ||
name: "moonx", | ||
args: { | ||
isVariadic: true, | ||
generators: generator, | ||
}, | ||
}; | ||
export default completionSpec; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function exec( | ||
command: string, | ||
wss: Array<string>, | ||
commands: Map<string, string[]>, | ||
) { | ||
const wokspaces = commands.get(command); | ||
if (!wokspaces) { | ||
throw new Error(`task ${command} does not exist`); | ||
} | ||
if (!wss.length) { | ||
return [`:${command}`]; | ||
} | ||
return wss | ||
.filter((ws) => wokspaces.includes(ws)) | ||
.map((ws) => `${ws}:${command}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function list( | ||
[command, ...wss]: Array<string>, | ||
commands: Map<string, string[]>, | ||
) { | ||
if (!commands.has(command) && wss.length) { | ||
console.log(`task ${command} does not exist`); | ||
return []; | ||
} | ||
if (!commands.has(command)) { | ||
return Array.from(commands.keys()); | ||
} | ||
const workspaces = commands.get(command)!; | ||
if (!wss.length) { | ||
return workspaces; | ||
} | ||
return workspaces.filter((ws) => !wss.includes(ws)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters