Last active
September 14, 2023 00:15
-
-
Save Jaid/99c1c4c2f1e1c27b9bc4c40ca94cdd79 to your computer and use it in GitHub Desktop.
TypeScript CLI entry point template
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
import type {ArgumentsCamelCase, Argv, CommandBuilder} from 'yargs' | |
import yargs from 'yargs' | |
import {hideBin} from 'yargs/helpers' | |
// Don’t fully understand this, taken from here: https://github.com/zwade/hypatia/blob/a4f2f5785c146b4cb4ebff44da609a6500c53887/backend/src/start.ts#L47 | |
export type Args = (typeof builder) extends CommandBuilder<any, infer U> ? ArgumentsCamelCase<U> : never | |
const handler = async (args: Args) => { | |
} | |
const builder = (argv: Argv) => { | |
return argv.options({ | |
}) | |
} | |
await yargs(hideBin(process.argv)) | |
.detectLocale(false) | |
.scriptName(process.env.npm_package_name!) | |
.command({ | |
builder, | |
command: `$0`, | |
handler, | |
}) | |
.parserConfiguration({ | |
'strip-aliased': true, | |
'strip-dashed': true, | |
}) | |
.parse() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment