Skip to content

Commit

Permalink
fix(typings): add type for options (#41)
Browse files Browse the repository at this point in the history
* type: add type for options

* docs: fix typo
  • Loading branch information
DiamondYuan authored May 30, 2020
1 parent f775d39 commit b2c6dac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class CloneCommand extends Command {
type: 'number',
description: 'Create a shallow clone with a history truncated to the specified number of commits',
},
});
};
}

* run({ argv }) {
Expand Down Expand Up @@ -176,7 +176,7 @@ this.options = {
alias: 'b',
demandOption: true,
description: 'the target directory',
coerce: str => path.resolve(prcess.cwd(), str),
coerce: str => path.resolve(process.cwd(), str),
},
depth: {
description: 'level to clone',
Expand Down
9 changes: 8 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arguments, Argv } from 'yargs';
import { Arguments, Argv, Options } from 'yargs';
import { ForkOptions, SpawnOptions } from 'child_process';
import * as dargs from 'dargs';

Expand Down Expand Up @@ -51,6 +51,13 @@ declare class CommonBin {

constructor(rawArgv?: string[]);


/**
* shortcut for yargs.options
* @param {Object} opt - an object set to `yargs.options`
*/
set options(opt: { [key: string]: Options });

/**
* command handler, could be generator / async function / normal function which return promise
* @param {Object} context - context object
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/ts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class CustomBin extends CommonBin {
console.info(this.context.cwd);
console.info(this.context.rawArgv.slice(0));
console.info(this.context.execArgv.slice(0));
this.options = {
depth: {
type: 'number',
description: 'Create a shallow clone with a history truncated to the specified number of commits',
},
};
}

errorHandler(e: Error) {
Expand Down

0 comments on commit b2c6dac

Please sign in to comment.