Skip to content

Commit

Permalink
feat: add ignoreArgv option (upgrade type-flag) (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Nov 10, 2022
1 parent b698ba4 commit 460a935
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,18 @@ Type: `Command[]`
Array of [commands](#commandoptions-callback) to register.
##### ignoreArgv
Type:
```ts
type IgnoreArgvCallback = (
type: 'known-flag' | 'unknown-flag' | 'argument',
flagOrArgv: string,
value: string | undefined,
) => boolean | void
```
A callback to ignore argv tokens from being parsed.
#### callback(parsed)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"dependencies": {
"terminal-columns": "^1.4.1",
"type-flag": "^2.1.0"
"type-flag": "^3.0.0"
},
"devDependencies": {
"@pvtnbr/eslint-config": "^0.33.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typeFlag from 'type-flag';
import { typeFlag } from 'type-flag';
import type {
CallbackFunction,
HasHelpOrVersion,
Expand Down Expand Up @@ -155,7 +155,13 @@ function cliBase<
};
}

const parsed = typeFlag(flags as HasHelpOrVersion<Options>, argv);
const parsed = typeFlag(
flags as HasHelpOrVersion<Options>,
argv,
{
ignore: options.ignoreArgv,
},
);

const showVersion = () => {
console.log(options.version);
Expand Down
11 changes: 10 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { TypeFlag, Flags as BaseFlags } from 'type-flag';
import type {
TypeFlag,
TypeFlagOptions,
Flags as BaseFlags,
} from 'type-flag';
import { Command } from './command';
import type { Renderers } from './render-help/renderers';

Expand Down Expand Up @@ -123,6 +127,11 @@ export type CliOptions<
Options to configure the help documentation. Pass in `false` to disable handling `--help, -h`.
*/
help?: false | HelpOptions;

/**
* Which argv elements to ignore from parsing
*/
ignoreArgv?: TypeFlagOptions['ignore'];
};

export type CliOptionsInternal<
Expand Down
2 changes: 1 addition & 1 deletion tests/cleye.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectType } from 'tsd';
import { cli, command } from '..';
import { cli, command } from '#cleye';

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

Expand Down
4 changes: 0 additions & 4 deletions tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"moduleResolution": "Node16",
"module": "Node16",
},
"include": ["."]
}
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
"compilerOptions": {
"strict": true,
"isolatedModules": true,
"moduleResolution": "node",
"esModuleInterop": true,

"module": "esnext",
"target": "esnext"
"module": "Node16"
},
"include": [
"src",
Expand Down

0 comments on commit 460a935

Please sign in to comment.