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

Switch from class to class-like to include all types in commander namespace #1081

Merged
merged 1 commit into from Oct 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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