Why does --version prints the bin name too?
aleclarson opened this issue Β· comments
This seems odd to me. If yarn
and npm
are anything to go by, the --version
flag should only print the version number. π
It's actually more common to see the binary or "display name" in the version output.:
$ go version
# go version go1.11.5 darwin/amd64
$ python3 -V
# Python 3.7.2
$ hugo version
# Hugo Static Site Generator v0.55.6/extended darwin/amd64 BuildDate: unknown
$ postgres -V
# postgres (PostgreSQL) 11.2
# ... more
That's fair, but those aren't JS programs ;D
Off the top of my head π
$ next --version
# Next.js v8.1.0
Hmm, maybe the version
method could have a 2nd argument for this? :P
This isn't a huge issue though, so I would understand if you'd prefer to not add the extra code!
Forgot to update you @aleclarson β you can customize the version content by overriding the _version
method of your program.
This is the default, accessing program name & its version thru this
access:
_version() {
console.log(`${this.bin}, ${this.ver}`);
}
To customize:
const prog = sade('foo');
// Customize `--version` output
// ~> printing the string directly instead `version()` setter
prog._version = () => console.log('v1.2.3');
Thank you @lukeed for the comment above, the _version override is what I also needed!
I had to tweak it slightly to get it to work in TypeScript, pasting here in case it is useful for others. This should've been enough:
const progAny = prog as any;
progAny._version = () => console.log(`ente ${getVersion()}`);
But we have the "no-explicit-any" TS eslint rule turned on. So we need the following more explicit code:
type ProgWithVersion = typeof prog & { _version: () => void };
(<ProgWithVersion>prog)._version = () => console.log(`ente ${getVersion()}`);