Skip to content

Instantly share code, notes, and snippets.

@Jaid
Last active September 14, 2023 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jaid/99c1c4c2f1e1c27b9bc4c40ca94cdd79 to your computer and use it in GitHub Desktop.
Save Jaid/99c1c4c2f1e1c27b9bc4c40ca94cdd79 to your computer and use it in GitHub Desktop.
TypeScript CLI entry point template
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