From 950d18ed1ef18746c69b597a0c340ce0e9924077 Mon Sep 17 00:00:00 2001 From: Jim Buck Date: Wed, 24 Oct 2018 23:32:49 -0400 Subject: [PATCH 1/2] Revert "Added Command methods. Got tests working." This reverts commit 858f2ba10daaa7c59a413ae022a4eb9a4394f1f4. --- vorpal/vorpal-tests.ts | 50 ++--------------------- vorpal/vorpal.d.ts | 92 ++++++++++++++---------------------------- 2 files changed, 34 insertions(+), 108 deletions(-) diff --git a/vorpal/vorpal-tests.ts b/vorpal/vorpal-tests.ts index 6650450f69..a1dd744648 100644 --- a/vorpal/vorpal-tests.ts +++ b/vorpal/vorpal-tests.ts @@ -1,50 +1,8 @@ -/// +/// -import {Vorpal} from './vorpal'; +let vorpal = require('vorpal'); -declare namespace app { - function execSQL(...args: any[]): PromiseLike; -} +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 ', '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 ', 'Switches prompt to another instance.') - .action(function (args, cb) { - instances[args.instance].show(); - cb(); - }) -} - -instances[0].show(); \ No newline at end of file diff --git a/vorpal/vorpal.d.ts b/vorpal/vorpal.d.ts index b327efe825..fcd189257f 100644 --- a/vorpal/vorpal.d.ts +++ b/vorpal/vorpal.d.ts @@ -4,38 +4,23 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -/// -import {} from 'inquirer'; -import {ParsedArgs} from 'minimist'; - -export type CallbackFunction = (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 = (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(command: string, cb: CallbackFunction): PromiseLike; - execSync(command: string, options: { fatal: boolean }): T; + execSync(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(choicesFn: CommandAutocompleteFn): this; // TODO: Revisit this. - action(actionFn: CommandActionFn): 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(actionFn: (command: string, callback: CallbackFunction) => void | T): this; } -type CommandParseFn = (command: string, args) => string; // TODO: Check args type. -type CommandValidateFn = (args) => boolean | string; // TODO: Check args type. -type CommandAutocompleteFn = (text: string, iteration: number, cb?: CallbackFunction) => void | PromiseLike; -type CommandActionFn = (args, cb?: CallbackFunction) => void | PromiseLike - -export var Vorpal: VorpalFactory; \ No newline at end of file +declare module "vorpal" { + export = VorpalInstance; +} From 2692e6b5b58dc8128828aa3c4a2098438e9cbec2 Mon Sep 17 00:00:00 2001 From: Jim Buck Date: Wed, 24 Oct 2018 23:32:55 -0400 Subject: [PATCH 2/2] Revert "Initial definition setup for Vorpal." This reverts commit b72b21bf19edf63d14149023adf1e0183f43c7eb. --- vorpal/vorpal-tests.ts | 8 --- vorpal/vorpal.d.ts | 117 ----------------------------------------- 2 files changed, 125 deletions(-) delete mode 100644 vorpal/vorpal-tests.ts delete mode 100644 vorpal/vorpal.d.ts diff --git a/vorpal/vorpal-tests.ts b/vorpal/vorpal-tests.ts deleted file mode 100644 index a1dd744648..0000000000 --- a/vorpal/vorpal-tests.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// - -let vorpal = require('vorpal'); - -let app: VorpalInstance = vorpal(); - -app - .parse(process.argv); diff --git a/vorpal/vorpal.d.ts b/vorpal/vorpal.d.ts deleted file mode 100644 index fcd189257f..0000000000 --- a/vorpal/vorpal.d.ts +++ /dev/null @@ -1,117 +0,0 @@ -// Type definitions for vorpal 1.11.4 -// Project: https://github.com/dthree/vorpal -// Definitions by: Jim Buck -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -declare type CallbackFunction = (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 {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[], options?: {use?: 'minimist'}): void; - - /** - * Sets the prompt delimiter for the given Vorpal instance. - * - * @param {string} str - * @returns {this} - */ - delimiter(str: string): this; - - /** - * 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. - */ - 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. - * - * @param {string} name - * @returns {Command} - */ - find(name: string): Command; - - exec(command: string, cb: CallbackFunction): PromiseLike; - - execSync(command: string, options: {fatal: boolean}): T; - - log(message: string, ...messages: string[]); - - history(id: string); - - localStorage(id: string); - - help(strBuilder: (cmd: string) => string); - - pipe(pipeFn: (stdout: string) => string); - - use(extension: string | Function); - - - /** - * Adds a new command to your command line API. - * - * @param {string} command - * @param {string} [description] - * @returns {Command} - */ - command(command: string, description?: string): Command; - - catch(command: string, description?: string): Command; - - mode(command: string, description?: string): Mode; -} - -declare interface UiInstance { - - redraw: RedrawMethod; - - delimiter(text?: string); - - input(text?: string); - - imprint(); - - submit(text: string); - - cancel(); -} - -declare interface RedrawMethod -{ - (text: string, ...texts: string[]); - - clear(); - done(); -} - -declare interface Command { - -} - -declare interface Mode { - description(desc: string): this; - - delimiter(str: string): this; - - init(initFn: (args: any, callback: CallbackFunction) => void): this; - - action(actionFn: (command: string, callback: CallbackFunction) => void | T): this; -} - -declare module "vorpal" { - export = VorpalInstance; -}