commands: create a dedicated commands directory

This commit is contained in:
2024-06-17 15:22:36 +08:00
parent fb6a75cb27
commit ca6dafa5f9
6 changed files with 248 additions and 151 deletions

10
commands/common.ts Normal file
View File

@@ -0,0 +1,10 @@
export function undefList<T, U>(opt: T | undefined, fn: (opt: T) => U) {
return opt === undefined ? [] : fn(opt)
}
export const optFlag = (flag: string, opt: string | undefined) => undefList(opt, opt => [flag, opt])
/**
* Generate a switch flag, like "--rebuild", "--nobuild"
*/
export const optSwitch = (flag: string, opt: boolean | undefined) => undefList(opt, opt => opt ? [flag] : [])