Skip to content

Commit 460a935

Browse files
feat: add ignoreArgv option (upgrade type-flag) (#18)
1 parent b698ba4 commit 460a935

8 files changed

+37
-17
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,18 @@ Type: `Command[]`
539539
540540
Array of [commands](#commandoptions-callback) to register.
541541
542+
##### ignoreArgv
543+
544+
Type:
545+
```ts
546+
type IgnoreArgvCallback = (
547+
type: 'known-flag' | 'unknown-flag' | 'argument',
548+
flagOrArgv: string,
549+
value: string | undefined,
550+
) => boolean | void
551+
```
552+
553+
A callback to ignore argv tokens from being parsed.
542554
543555
#### callback(parsed)
544556

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
},
5555
"dependencies": {
5656
"terminal-columns": "^1.4.1",
57-
"type-flag": "^2.1.0"
57+
"type-flag": "^3.0.0"
5858
},
5959
"devDependencies": {
6060
"@pvtnbr/eslint-config": "^0.33.0",

pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import typeFlag from 'type-flag';
1+
import { typeFlag } from 'type-flag';
22
import type {
33
CallbackFunction,
44
HasHelpOrVersion,
@@ -155,7 +155,13 @@ function cliBase<
155155
};
156156
}
157157

158-
const parsed = typeFlag(flags as HasHelpOrVersion<Options>, argv);
158+
const parsed = typeFlag(
159+
flags as HasHelpOrVersion<Options>,
160+
argv,
161+
{
162+
ignore: options.ignoreArgv,
163+
},
164+
);
159165

160166
const showVersion = () => {
161167
console.log(options.version);

src/types.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { TypeFlag, Flags as BaseFlags } from 'type-flag';
1+
import type {
2+
TypeFlag,
3+
TypeFlagOptions,
4+
Flags as BaseFlags,
5+
} from 'type-flag';
26
import { Command } from './command';
37
import type { Renderers } from './render-help/renderers';
48

@@ -123,6 +127,11 @@ export type CliOptions<
123127
Options to configure the help documentation. Pass in `false` to disable handling `--help, -h`.
124128
*/
125129
help?: false | HelpOptions;
130+
131+
/**
132+
* Which argv elements to ignore from parsing
133+
*/
134+
ignoreArgv?: TypeFlagOptions['ignore'];
126135
};
127136

128137
export type CliOptionsInternal<

tests/cleye.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expectType } from 'tsd';
2-
import { cli, command } from '..';
2+
import { cli, command } from '#cleye';
33

44
type Arguments = string[] & { '--': string[] };
55

tests/tsconfig.json

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
22
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"moduleResolution": "Node16",
5-
"module": "Node16",
6-
},
73
"include": ["."]
84
}

tsconfig.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
"compilerOptions": {
33
"strict": true,
44
"isolatedModules": true,
5-
"moduleResolution": "node",
65
"esModuleInterop": true,
7-
8-
"module": "esnext",
9-
"target": "esnext"
6+
"module": "Node16"
107
},
118
"include": [
129
"src",

0 commit comments

Comments
 (0)