Skip to content

Commit

Permalink
Switch from class to class-like to include all types in commander nam…
Browse files Browse the repository at this point in the history
…espace
  • Loading branch information
shadowspawn committed Oct 30, 2019
1 parent 08a5f02 commit 41c6985
Showing 1 changed file with 11 additions and 34 deletions.
45 changes: 11 additions & 34 deletions typings/index.d.ts
Expand Up @@ -5,18 +5,17 @@

///<reference types="node" />

declare namespace local {
declare namespace commander {

class CommanderError extends Error {
interface CommanderError extends Error {
code: string;
exitCode: number;
message: string;
nestedError?: string;

constructor(exitCode: number, code: string, message: string);
}
type CommanderErrorConstructor = { new (exitCode: number, code: string, message: string): CommanderError };

class Option {
interface Option {
flags: string;
required: boolean; // A value must be supplied when the option is specified.
optional: boolean; // A value is optional when the option is specified.
Expand All @@ -25,28 +24,14 @@ declare namespace local {
short?: string;
long: string;
description: string;

/**
* Initialize a new `Option` with the given `flags` and `description`.
*
* @param {string} flags
* @param {string} [description]
*/
constructor(flags: string, description?: string);
}
type OptionConstructor = { new (flags: string, description?: string): Option };

class Command extends NodeJS.EventEmitter {
interface Command extends NodeJS.EventEmitter {
[key: string]: any; // options as properties

args: string[];

/**
* Initialize a new `Command`.
*
* @param {string} [name]
*/
constructor(name?: string);

/**
* Set the program version to `str`.
*
Expand Down Expand Up @@ -78,7 +63,7 @@ declare namespace local {
* @param opts - configuration options
* @returns new command
*/
command(nameAndArgs: string, opts?: commander.CommandOptions): Command;
command(nameAndArgs: string, opts?: CommandOptions): Command;
/**
* Define a command, implemented in a separate executable file.
*
Expand Down Expand Up @@ -291,14 +276,8 @@ declare namespace local {
*/
help(cb?: (str: string) => string): never;
}
type CommandConstructor = { new (name?: string): Command };

}

declare namespace commander {

type Command = local.Command

type Option = local.Option

interface CommandOptions {
noHelp?: boolean;
Expand All @@ -312,11 +291,9 @@ declare namespace commander {
}

interface CommanderStatic extends Command {
Command: typeof local.Command;
Option: typeof local.Option;
CommandOptions: CommandOptions;
ParseOptionsResult: ParseOptionsResult;
CommanderError : typeof local.CommanderError;
Command: CommandConstructor;
Option: OptionConstructor;
CommanderError:CommanderErrorConstructor;
}

}
Expand Down

0 comments on commit 41c6985

Please sign in to comment.