(cli): "-v" options cannot be used as an alias for verbose
ACHP opened this issue · 3 comments
"-v" is actually used by sade
as an alias for "version"
How to reproduce
skott index.android.js index.js -v
Actual
it will returns something like
skott, 0.28.2
Expected
It should print the logs like when specifying "--verbose"
Hello @ACHP, nice catch!
I'm not really using aliases myself so never noticed that actually. I think that sade
default behavior should not be overridden, so we could find a new alias composed of 2 letters. Do you have any suggestions? You can even land a small PR directly if you want :)
I tried monkey patching my current skott install and tried with -vv
instead but it still not working.
I think that sade expect alias to be 1 char long.
To test my hypothesis, I tried using -ee
(since you already use -e
for the fileExtensions options).
And when I log the options I see:
{
e: [ '', '' ],
/*...*/
ee: false,
}
And the error message is Error: options.fileExtensions.split is not a function
, which seems to validate my hypothesis.
I didn't manage to find a sade documentation about this. (But honestly I didn't search for long)
I also tried using -ts
instead of --tsconfig
as documented, but it didn't worked :/
skott index.android.js --tsconfig "./yolo.json"
# tsconfig: 'yolo.json', ts: 'yolo.json' ✅ Works as expected
skott index.android.js --tsconfig="./yolo.json"
# tsconfig: 'yolo.json', ts: 'yolo.json' ✅ Works as expected
skott index.android.js -ts "./yolo.json"
# tsconfig: 'tsconfig.json', ts: 'tsconfig.json', t: true, s: true ❌ does not work as expected
skott index.android.js --ts "./yolo.json"
# tsconfig: 'yolo.json', ts: 'yolo.json' 🟧 Works but shouldn't IMO (only `--tsconfig` or `-ts` should work `--ts` shouldn't)
skott index.android.js --ts="./yolo.json"
# tsconfig: 'yolo.json', ts: 'yolo.json' 🟧 Works but shouldn't IMO (only `--tsconfig` or `-ts` should work `--ts` shouldn't)
Conclusion
I don't know sade
very well and to be honest I didn't spent much time on the doc, but I think it behave a bit weird ...
I would recommand
- trying
commander
to compare the behaviors, and see it it works "better" (more work but no change from the user perspective) - Or replace all alias that contains 2 char to use one char, probably uppercase to avoid conflict (easier, but requires to update the documentation) (and to answer your question, I would use
-V
for verbose, of-vv
if it worked)
Thanks for this complete investigation!
Yes you're right, it seems that sade doesn't ignore multi char alias but requires a double dash --
instead of one dash like the docs show it (when running skott --help
) so it's a bit inconsistent and misleading imho.
About one of your suggestions to avoid conflicts I just tested and it seems that the parser makes a difference between uppercased and lowercased flags, so skott -v
or skott -V
don't map to the same option but I'm not really a fan of that solution to avoid conflicts to be honest, I feel like uppercase/lowercase is not explicit enough to express different options, skott -v
printing the version and skott -V
enabling verbose/debug mode is misleading as hell.
Commander seems to work as expected towards the already established aliases for skott, that is multi char alias with one dash:
import { Command } from 'commander';
const program = new Command();
program
.option('-vb, --verbose')
program.parse();
console.log(program.opts());
With the following command: node index.js -vb
, commander actually prints Options: { verbose: true }
.
So we could actually switch to commander, it should be easy as the whole CLI initialization is done in this file https://github.com/antoine-coulon/skott/blob/main/packages/skott/bin/cli.ts.