Skip to content

Commit 8dd312b

Browse files
committed
fix: flags can go in any order — dad --with=pi workos/cli#139 works
1 parent 7e6543a commit 8dd312b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

packages/cli/src/cli.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,22 @@ async function configCommand(): Promise<number> {
280280
}
281281

282282
async function main(argv: string[]): Promise<number> {
283-
const [cmd, ...rest] = argv;
283+
const positional = argv.filter((a) => !a.startsWith('--'));
284+
const [cmd, ...rest] = positional;
284285

285-
if (!cmd || cmd === '--help' || cmd === '-h' || cmd === 'help') {
286+
if (!cmd || cmd === '-h' || cmd === 'help') {
286287
console.log(USAGE);
287288
return 0;
288289
}
289290

290-
if (cmd === '--version' || cmd === '-v' || cmd === '-V') {
291+
if (cmd === '-v' || cmd === '-V') {
292+
const pkg = await import('../../../package.json');
293+
console.log(pkg.version ?? '0.0.0');
294+
return 0;
295+
}
296+
297+
if (argv.includes('--help')) { console.log(USAGE); return 0; }
298+
if (argv.includes('--version')) {
291299
const pkg = await import('../../../package.json');
292300
console.log(pkg.version ?? '0.0.0');
293301
return 0;

0 commit comments

Comments
 (0)