-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): support camelCase flags (deprecate kebab-case flags) (#688)
* feat: support camel case flags * ci: add E2E tests * ci: fix build tests * ci: fix Bun tests * ci: add unit tests * chore: remove all kebab options * chore: remove all kebab options * docs: update docs to camel case flags
- Loading branch information
1 parent
85b6b3b
commit 203fb45
Showing
28 changed files
with
300 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const regex = /-/g; | ||
|
||
export const toDynamicCase = (str: string) => { | ||
// Short flags | ||
if (str[1] !== '-') { | ||
return str; | ||
} | ||
|
||
const [flag, ...args] = str.slice(2).split('='); | ||
const dynamicCase = flag.toLowerCase().replace(regex, ''); | ||
|
||
let processArg = `--${dynamicCase}`; | ||
|
||
if (args.length > 0) { | ||
processArg += `=${args.join('=')}`; | ||
} | ||
|
||
return processArg; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { describe } from '../../src/modules/helpers/describe.js'; | ||
import { it } from '../../src/modules/helpers/it/core.js'; | ||
import { assert } from '../../src/modules/essentials/assert.js'; | ||
import { inspectPoku, isBuild } from '../__utils__/capture-cli.test.js'; | ||
import { skip } from '../../src/modules/helpers/skip.js'; | ||
|
||
if (isBuild) { | ||
skip(); | ||
} | ||
|
||
describe('CLI Flags', async () => { | ||
await it('Short flags', async () => { | ||
const output = await inspectPoku('-d -p', { | ||
cwd: 'test/__fixtures__/e2e/no-tests', | ||
}); | ||
|
||
assert.strictEqual(output.exitCode, 0, 'Exit Code needs to be 0'); | ||
assert( | ||
/debug(.+)?:(.+)?true/.test(output.stdout), | ||
'CLI needs to able "debug"' | ||
); | ||
assert( | ||
/parallel(.+)?:(.+)?true/.test(output.stdout), | ||
'CLI needs to able "parallel"' | ||
); | ||
}); | ||
|
||
await it('Kebab flags', async () => { | ||
const output = await inspectPoku('--debug --fail-fast --deno-cjs=js,cjs', { | ||
cwd: 'test/__fixtures__/e2e/no-tests', | ||
}); | ||
|
||
assert.strictEqual(output.exitCode, 0, 'Exit Code needs to be 0'); | ||
assert( | ||
/debug(.+)?:(.+)?true/.test(output.stdout), | ||
'CLI needs to able "debug"' | ||
); | ||
assert( | ||
/failFast(.+)?:(.+)?true/.test(output.stdout), | ||
'CLI needs to able "failFast"' | ||
); | ||
assert( | ||
/cjs(.+)?:(.+)?js(.+)?cjs/.test(output.stdout), | ||
'CLI needs to able "Deno CJS Pollyfill"' | ||
); | ||
}); | ||
|
||
await it('Camel flags', async () => { | ||
const output = await inspectPoku('--debug --failFast --denoCjs=js,cjs', { | ||
cwd: 'test/__fixtures__/e2e/no-tests', | ||
}); | ||
|
||
assert.strictEqual(output.exitCode, 0, 'Exit Code needs to be 0'); | ||
assert( | ||
/debug(.+)?:(.+)?true/.test(output.stdout), | ||
'CLI needs to able "debug"' | ||
); | ||
assert( | ||
/failFast(.+)?:(.+)?true/.test(output.stdout), | ||
'CLI needs to able "failFast"' | ||
); | ||
assert( | ||
/cjs(.+)?:(.+)?js(.+)?cjs/.test(output.stdout), | ||
'CLI needs to able "Deno CJS Pollyfill"' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe } from '../../src/modules/helpers/describe.js'; | ||
import { it } from '../../src/modules/helpers/it/core.js'; | ||
import { assert } from '../../src/modules/essentials/assert.js'; | ||
import { toDynamicCase } from '../../src/parsers/to-dynamic-case.js'; | ||
|
||
describe('Dynamic Flag Cases', () => { | ||
it('General', () => { | ||
assert.strictEqual(toDynamicCase('-d'), '-d', 'Short Flag (lower)'); | ||
assert.strictEqual(toDynamicCase('-D'), '-D', 'Short Flag (upper)'); | ||
assert.strictEqual(toDynamicCase('--debug'), '--debug', 'Single Word'); | ||
}); | ||
|
||
it('Kebab Case', () => { | ||
assert.strictEqual(toDynamicCase('--fast-fail'), '--fastfail', 'Two Words'); | ||
assert.strictEqual( | ||
toDynamicCase('--fast-fail-test'), | ||
'--fastfailtest', | ||
'Multiple Words' | ||
); | ||
assert.strictEqual( | ||
toDynamicCase('--fast-fail=test'), | ||
'--fastfail=test', | ||
'Arg' | ||
); | ||
assert.strictEqual( | ||
toDynamicCase('--fast-fail=test-Test'), | ||
'--fastfail=test-Test', | ||
'Kebab Arg' | ||
); | ||
assert.strictEqual( | ||
toDynamicCase('--fast-fail="test-Test=test-Test"'), | ||
'--fastfail="test-Test=test-Test"', | ||
'Deep Args' | ||
); | ||
}); | ||
|
||
it('Camel Case', () => { | ||
assert.strictEqual(toDynamicCase('--fastFail'), '--fastfail', 'Two Words'); | ||
assert.strictEqual( | ||
toDynamicCase('--fastFailTest'), | ||
'--fastfailtest', | ||
'Multiple Words' | ||
); | ||
assert.strictEqual( | ||
toDynamicCase('--fastFail=test'), | ||
'--fastfail=test', | ||
'Arg' | ||
); | ||
assert.strictEqual( | ||
toDynamicCase('--fastFail=testTest'), | ||
'--fastfail=testTest', | ||
'Camel Arg' | ||
); | ||
assert.strictEqual( | ||
toDynamicCase('--fastFail="testTest=testTest"'), | ||
'--fastfail="testTest=testTest"', | ||
'Deep Args' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.