Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript type declaration file #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Corrects a distinction between parsing configuration and parser confi…
…guration
  • Loading branch information
adamvoss committed Jul 21, 2017
commit c2ffacaba084385edafb191b18d06e6535f55f38
39 changes: 34 additions & 5 deletions lib/dashdash.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
/// <reference types="node" />

export class Parser {
constructor(config: ParseConfiguration);
constructor(config: ParserConfiguration);

bashCompletion(args: BashCompletionConfiguration): string;

help(config?: HelpConfiguration): string;

parse(inputs?: string[]): Results;
parse(inputs?: string[] | ParsingConfiguration): Results;
}

export function addOptionType(optionType: OptionType): void;
Expand All @@ -19,11 +19,11 @@ export function bashCompletionFromOptions(args: BashCompletionConfiguration): st

export function bashCompletionSpecFromOptions(args: BashCompletionSpecConfiguration): string;

export function createParser(config: ParseConfiguration): Parser;
export function createParser(config: ParserConfiguration): Parser;

export function getOptionType(name: string): OptionType;

export function parse(config: ParseConfiguration): Results;
export function parse(config: ParsingConfiguration): Results;

export interface Results {
[key: string]: any;
Expand All @@ -44,7 +44,7 @@ export function synopsisFromOpt(o: Option): string;

export type Option = OptionWithoutAliases | OptionWithAliases;

export interface ParseConfiguration {
export interface ParsingConfiguration {
/**
* The argv to parse. Defaults to `process.argv`.
*/
Expand All @@ -63,6 +63,35 @@ export interface ParseConfiguration {
options?: Array<Option | Group>;
}

export interface ParserConfiguration {
/**
* Array of option specs.
*/
options: Array<Option | Group>;

/**
* Whether to throw on unknown options.
* If false, then unknown args are included in the _args array.
* Default: false
*/
allowUnknown?: boolean;

/**
* Whether to allow interspersed arguments (non-options) and options.
*
* E.g.:
* node tool.js arg1 arg2 -v
*
* '-v' is after some args here. If `interspersed: false` then '-v'
* would not be parsed out. Note that regardless of `interspersed`
* the presence of '--' will stop option parsing, as all good
* option parsers should.
*
* Default: true
*/
interspersed?: boolean;
}

export interface OptionWithoutAliases extends OptionBase {
/**
* The option name
Expand Down