lukeed / lukeed/tsm

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

Open
#22 0 comments 6 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.2k
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the behavior with the mentioned my-cli.ts shebang and the ./my-cli.ts -h and ./my-cli.ts -v commands, then compare it with the my-cli.js and node shebang example. Trace how tsm handles shebang arguments; done means the script receives -h and -v so it prints its own help and version output.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.