mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Revert "Added Command methods. Got tests working."
This reverts commit 858f2ba10d.
This commit is contained in:
+4
-46
@@ -1,50 +1,8 @@
|
||||
///<reference path="./vorpal.d.ts"/>
|
||||
///<reference path="vorpal.d.ts"/>
|
||||
|
||||
import {Vorpal} from './vorpal';
|
||||
let vorpal = require('vorpal');
|
||||
|
||||
declare namespace app {
|
||||
function execSQL(...args: any[]): PromiseLike<any>;
|
||||
}
|
||||
let app: VorpalInstance = vorpal();
|
||||
|
||||
// Constructor
|
||||
let vorpal = new Vorpal();
|
||||
|
||||
// new-less Constructor
|
||||
let newLessApp = Vorpal();
|
||||
|
||||
// Parse
|
||||
vorpal
|
||||
.show()
|
||||
app
|
||||
.parse(process.argv);
|
||||
|
||||
// Parse Options
|
||||
var results = vorpal.parse('foo -baz', { use: 'minimist' });
|
||||
|
||||
new Vorpal().delimiter('unicorn-approved-app$');
|
||||
|
||||
// Show
|
||||
|
||||
vorpal
|
||||
.delimiter('pg-cli:')
|
||||
.show();
|
||||
|
||||
vorpal
|
||||
.command('sql <query>', 'Executes arbitrary sql.')
|
||||
.action(function (args) {
|
||||
return app.execSQL(args.query);
|
||||
});
|
||||
|
||||
// Show (multiple instances)
|
||||
|
||||
var instances = [];
|
||||
for (var i = 0; i < 3; ++i) {
|
||||
instances[i] = new Vorpal()
|
||||
.delimiter('instance' + i + '~$')
|
||||
.command('switch <instance>', 'Switches prompt to another instance.')
|
||||
.action(function (args, cb) {
|
||||
instances[args.instance].show();
|
||||
cb();
|
||||
})
|
||||
}
|
||||
|
||||
instances[0].show();
|
||||
Vendored
+30
-62
@@ -4,38 +4,23 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../inquirer/inquirer.d.ts" />
|
||||
/// <reference path="../minimist/minimist.d.ts" />
|
||||
|
||||
import {} from 'inquirer';
|
||||
import {ParsedArgs} from 'minimist';
|
||||
|
||||
export type CallbackFunction<T> = (err?: string | Error, data?: T) => void;
|
||||
|
||||
interface TypesDefinition
|
||||
{
|
||||
string?: string[];
|
||||
number?: string[];
|
||||
// TODO: Check other types.
|
||||
}
|
||||
|
||||
interface VorpalFactory {
|
||||
new (): VorpalInstance;
|
||||
|
||||
(): VorpalInstance;
|
||||
}
|
||||
|
||||
interface VorpalInstance {
|
||||
declare type CallbackFunction<T> = (err: string | Error, data: T) => void;
|
||||
|
||||
declare interface VorpalInstance {
|
||||
|
||||
ui: UiInstance;
|
||||
|
||||
constructor();
|
||||
|
||||
/**
|
||||
* Parses the process's `process.argv` arguments and executes the matching command.
|
||||
*
|
||||
* @param {(string|string[])} argv
|
||||
* @param {{use?: 'minimist'}} [options] When `use: 'minimist'` is passed in as an option, `.parse` will instead expose the `minimist` module's main method and return the results, executing no commands.
|
||||
* @param {IArguments} argv
|
||||
* @param {*} options When `use: 'minimist'` is passed in as an option, `.parse` will instead expose the `minimist` module's main method and return the results, executing no commands.
|
||||
*/
|
||||
parse(argv: string | string[], options?: { use?: 'minimist' }): ParsedArgs;
|
||||
|
||||
parse(argv: string[], options?: {use?: 'minimist'}): void;
|
||||
|
||||
/**
|
||||
* Sets the prompt delimiter for the given Vorpal instance.
|
||||
*
|
||||
@@ -46,12 +31,11 @@ interface VorpalInstance {
|
||||
|
||||
/**
|
||||
* Attaches the TTY's CLI prompt to that given instance of Vorpal.
|
||||
* As a note, multiple instances of Vorpal can run in the same Node instance. However, only one can be 'attached' to your TTY. The last instance given the show() command will be attached, and the previously shown instances will detach.
|
||||
*
|
||||
* @returns {this}
|
||||
* As a note, multiple instances of Vorpal can run in the same Node instance. However, only one can be 'attached' to your TTY. The last instance given the show() command will be attached, and the previously shown instances will detach.
|
||||
*/
|
||||
show(): this;
|
||||
|
||||
show(): void;
|
||||
|
||||
/**
|
||||
* Returns a given command by its name. This is used instead of `vorpal.command()` as `.command` will overwrite a given command. If command is not found, `undefined` is returned.
|
||||
*
|
||||
@@ -62,12 +46,12 @@ interface VorpalInstance {
|
||||
|
||||
exec<T>(command: string, cb: CallbackFunction<T>): PromiseLike<T>;
|
||||
|
||||
execSync<T>(command: string, options: { fatal: boolean }): T;
|
||||
execSync<T>(command: string, options: {fatal: boolean}): T;
|
||||
|
||||
log(message: string, ...messages: string[]);
|
||||
|
||||
|
||||
history(id: string);
|
||||
|
||||
|
||||
localStorage(id: string);
|
||||
|
||||
help(strBuilder: (cmd: string) => string);
|
||||
@@ -76,7 +60,7 @@ interface VorpalInstance {
|
||||
|
||||
use(extension: string | Function);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new command to your command line API.
|
||||
*
|
||||
@@ -91,47 +75,34 @@ interface VorpalInstance {
|
||||
mode(command: string, description?: string): Mode;
|
||||
}
|
||||
|
||||
export interface UiInstance {
|
||||
declare interface UiInstance {
|
||||
|
||||
redraw: RedrawMethod;
|
||||
|
||||
delimiter(text?: string);
|
||||
|
||||
input(text?: string);
|
||||
|
||||
|
||||
imprint();
|
||||
|
||||
submit(text: string);
|
||||
|
||||
|
||||
cancel();
|
||||
}
|
||||
|
||||
export function RedrawMethod(text: string): void;
|
||||
export function RedrawMethod(...texts: string[]): void;
|
||||
declare interface RedrawMethod
|
||||
{
|
||||
(text: string, ...texts: string[]);
|
||||
|
||||
export interface RedrawMethod {
|
||||
clear(): void;
|
||||
done(): void;
|
||||
clear();
|
||||
done();
|
||||
}
|
||||
|
||||
export interface Command {
|
||||
description(description: string): this;
|
||||
alias(name: string): this;
|
||||
alias(...names: string[]): this;
|
||||
parse(parseFn: CommandParseFn): this;
|
||||
option(flag: string, description: string, autocomplete: string[]): this; // TODO: Check autocomplete types.
|
||||
types(types: TypesDefinition): this;
|
||||
hidden(): this; // TODO: Check return type.
|
||||
remove(); // TODO: Check return type.
|
||||
help(helpFn: (args) => void); // TODO: Check args type.
|
||||
validate(validateFn: CommandValidateFn);
|
||||
autocomplete(choices: string[]): this;
|
||||
autocomplete(choices: {}): this; // TODO: Revisit this.
|
||||
autocomplete<T>(choicesFn: CommandAutocompleteFn<T>): this; // TODO: Revisit this.
|
||||
action<T>(actionFn: CommandActionFn<T>): this;
|
||||
declare interface Command {
|
||||
|
||||
}
|
||||
|
||||
export interface Mode {
|
||||
declare interface Mode {
|
||||
description(desc: string): this;
|
||||
|
||||
delimiter(str: string): this;
|
||||
@@ -141,9 +112,6 @@ export interface Mode {
|
||||
action<T>(actionFn: (command: string, callback: CallbackFunction<void | T>) => void | T): this;
|
||||
}
|
||||
|
||||
type CommandParseFn = (command: string, args) => string; // TODO: Check args type.
|
||||
type CommandValidateFn = (args) => boolean | string; // TODO: Check args type.
|
||||
type CommandAutocompleteFn<T> = (text: string, iteration: number, cb?: CallbackFunction<T>) => void | PromiseLike<T>;
|
||||
type CommandActionFn<T> = (args, cb?: CallbackFunction<T>) => void | PromiseLike<T>
|
||||
|
||||
export var Vorpal: VorpalFactory;
|
||||
declare module "vorpal" {
|
||||
export = VorpalInstance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user