Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tsm as shebang should allow scripts to respond to --help and --version #22

@BoruiGu

Description

@BoruiGu

for example given this my-cli.ts script

#!/usr/bin/env tsm

if (process.argv.includes('-h') || process.argv.includes('--help')) {
    console.log('my-cli help')
    process.exit(0)
}

if (process.argv.includes('-v') || process.argv.includes('--version')) {
    console.log(`my-cli version'`)
    process.exit(0)
}

when i run ./my-cli.ts -h or ./my-cli.ts -v, i would expect it to output the help / version of my-cli

however currently the help / version of tsm gets printed instead

in contrast, it behaves as expected when using node in shebang. if changing it to my-cli.js

#!/usr/bin/env node

if (process.argv.includes('-h') || process.argv.includes('--help')) {
    console.log('my-cli help')
    process.exit(0)
}

if (process.argv.includes('-v') || process.argv.includes('--version')) {
    console.log(`my-cli version'`)
    process.exit(0)
}

and run ./my-cli.js -h or ./my-cli.js -v, it correctly output the help / version of my-cli

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions