Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cli-engine-command

Package Overview
Dependencies
Maintainers
3
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-engine-command - npm Package Compare versions

Comparing version 10.0.0-ts.4 to 10.0.0-ts.5

22

lib/command.d.ts
import { Config, ConfigOptions, Plugin } from 'cli-engine-config';
import { HTTP } from 'http-call';
import { CLI } from 'cli-ux';
import { IArg } from 'cli-flags';
import { IFlag } from './flags';
export declare type MockReturn<T extends Command> = {
cmd: T;
stdout: string;
stderr: string;
};
export declare type CommandRunFn = <T extends Command>(this: CommandClass<T>, config?: ConfigOptions) => Promise<T>;
export declare type CommandMockFn = <T extends Command>(this: CommandClass<T>, ...argv: string[]) => Promise<MockReturn<T>>;
export interface CommandClass<T extends Command> {

@@ -9,4 +16,5 @@ new ({config}: {

}): T;
run: CommandRunFn;
mock: CommandMockFn;
}
export declare function run<T extends Command>(Command: CommandClass<T>, config?: ConfigOptions): Promise<T>;
export declare class Command {

@@ -22,3 +30,3 @@ static topic: string;

static flags: {
[name: string]: any;
[name: string]: IFlag<any>;
};

@@ -32,12 +40,10 @@ static args: IArg[];

*/
static mock(...argv: string[]): Promise<Command>;
static mock: CommandMockFn;
/**
* instantiate and run the command
*/
static run(config?: ConfigOptions): Promise<Command>;
static run: CommandRunFn;
readonly ctor: typeof Command;
config: Config;
http: typeof HTTP;
cli: CLI;
out: CLI;
flags: {

@@ -65,6 +71,4 @@ [name: string]: any;

run(): Promise<void>;
readonly stdout: string;
readonly stderr: string;
static buildHelp(config: Config): string;
static buildHelpLine(config: Config): [string, string | undefined];
}

@@ -9,18 +9,4 @@ "use strict";

const cli_flags_1 = require("cli-flags");
async function run(Command, config) {
const cmd = new Command({ config });
try {
await cmd.init();
await cmd.run();
await cmd.out.done();
}
catch (err) {
cmd.out.error(err);
}
return cmd;
}
exports.run = run;
class Command {
constructor(options = {}) {
// TODO: no any
this.flags = {};

@@ -30,5 +16,2 @@ this.args = {};

this.argv = this.config.argv;
const { cli } = require('cli-ux');
this.out = this.cli = cli;
this.out.color = require('./color').color;
this.http = http_call_1.HTTP.defaults({

@@ -48,16 +31,2 @@ headers: {

}
/**
* instantiate and run the command setting {mock: true} in the config (shorthand method)
*/
static async mock(...argv) {
cli_ux_1.cli.warn('command.mock() is deprecated. Use cli-engine-test');
argv.unshift('cmd');
return this.run({ argv, mock: true });
}
/**
* instantiate and run the command
*/
static run(config) {
return run(this, config);
}
get ctor() {

@@ -81,8 +50,2 @@ return this.constructor;

async run() { }
get stdout() {
return this.out.stdout.output;
}
get stderr() {
return this.out.stderr.output;
}
static buildHelp(config) {

@@ -101,2 +64,29 @@ let help = new help_1.default(config);

Command._version = pjson.version;
/**
* instantiate and run the command setting {mock: true} in the config (shorthand method)
*/
Command.mock = async function (...argv) {
argv.unshift('cmd');
const cmd = await this.run({ argv, mock: true });
return {
cmd,
stdout: cli_ux_1.cli.stdout.output,
stderr: cli_ux_1.cli.stderr.output,
};
};
/**
* instantiate and run the command
*/
Command.run = async function (config) {
const cmd = new this({ config });
try {
await cmd.init();
await cmd.run();
await cli_ux_1.cli.done();
}
catch (err) {
cli_ux_1.cli.error(err);
}
return cmd;
};
exports.Command = Command;

@@ -24,3 +24,3 @@ import { Config } from 'cli-engine-config';

export declare type CompletionOptionFlag<T> = IOptionFlag<T> & withCompletion;
export declare type FlagBuilder<T> = {
export declare type FlagBuilder<T = string> = {
(options: Partial<IMultiOptionFlag<T>> & {

@@ -34,2 +34,3 @@ multiple: true;

};
export declare type IFlag<T> = IBooleanFlag | CompletionOptionFlag<T>;
export declare const flags: {

@@ -36,0 +37,0 @@ option: <T = string>(defaults?: Partial<IOptionalFlag<T> & withCompletion> | Partial<IRequiredFlag<T> & withCompletion> | Partial<IMultiOptionFlag<T> & withCompletion>) => FlagBuilder<T>;

@@ -1,3 +0,3 @@

export { Command as default, Command, run, CommandClass } from './command';
export { Command as default, Command } from './command';
export { Topic } from './topic';
export { flags, Completion } from './flags';
export { flags, Completion, FlagBuilder } from './flags';

@@ -6,3 +6,2 @@ "use strict";

exports.Command = command_1.Command;
exports.run = command_1.run;
var topic_1 = require("./topic");

@@ -9,0 +8,0 @@ exports.Topic = topic_1.Topic;

{
"name": "cli-engine-command",
"description": "base CLI command for cli-engine",
"version": "10.0.0-ts.4",
"version": "10.0.0-ts.5",
"author": "Jeff Dickey @jdxcode",

@@ -12,3 +12,3 @@ "bugs": "https://github.com/heroku/cli-engine-command/issues",

"chalk": "2.3.0",
"cli-flags": "1.0.17",
"cli-flags": "1.0.18",
"cli-ux": "^2.0.5",

@@ -29,3 +29,3 @@ "fs-extra": "^5.0.0",

"@types/supports-color": "3.1.0",
"cli-engine-config": "4.0.1-ts.22",
"cli-engine-config": "ts",
"del-cli": "1.1.0",

@@ -32,0 +32,0 @@ "husky": "^0.14.3",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc