Socket
Socket
Sign inDemoInstall

clipanion

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clipanion - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0-rc.1

29

lib/advanced/Cli.d.ts

@@ -34,2 +34,6 @@ /// <reference types="node" />

stderr: Writable;
/**
* Whether colors should be enabled.
*/
colorDepth: number;
};

@@ -39,6 +43,6 @@ export declare type CliContext<Context extends BaseContext> = {

};
export declare type UserContextKeys<Context extends BaseContext> = Exclude<keyof Context, keyof BaseContext>;
export declare type UserContext<Context extends BaseContext> = Pick<Context, UserContextKeys<Context>>;
export declare type PartialContext<Context extends BaseContext> = UserContextKeys<Context> extends never ? Partial<Pick<Context, keyof BaseContext>> | undefined | void : Partial<Pick<Context, keyof BaseContext>> & UserContext<Context>;
export declare type RunContext<Context extends BaseContext> = Context | PartialContext<Context>;
export declare type UserContextKeys<BaseContext, Context extends BaseContext> = Exclude<keyof Context, keyof BaseContext>;
export declare type UserContext<BaseContext, Context extends BaseContext> = Pick<Context, UserContextKeys<BaseContext, Context>>;
export declare type PartialContext<BaseContext, Context extends BaseContext> = UserContextKeys<BaseContext, Context> extends never ? Partial<Pick<Context, keyof BaseContext>> | undefined | void : Partial<Pick<Context, keyof BaseContext>> & UserContext<BaseContext, Context>;
export declare type RunContext<BaseContext, Context extends BaseContext> = Context | PartialContext<BaseContext, Context>;
export declare type CliOptions = Readonly<{

@@ -73,8 +77,6 @@ /**

/**
* If `true`, the Cli will use colors in the output.
*
* @default
* process.env.FORCE_COLOR ?? process.stdout.isTTY
* If `true`, the Cli will use colors in the output. If `false`, it won't.
* If `undefined`, Clipanion will infer the correct value from the env.
*/
enableColors: boolean;
enableColors?: boolean;
}>;

@@ -143,2 +145,3 @@ export declare type MiniCli<Context extends BaseContext> = CliOptions & {

};
colorDepth: number;
};

@@ -155,3 +158,3 @@ private readonly builder;

readonly enableCapture: boolean;
readonly enableColors: boolean;
readonly enableColors?: boolean;
/**

@@ -170,3 +173,3 @@ * Creates a new Cli and registers all commands passed as parameters.

process(input: Array<string>): Command<Context>;
run(input: Command<Context> | Array<string>, userContext: RunContext<Context>): Promise<number>;
run(input: Command<Context> | Array<string>, userContext: RunContext<BaseContext, Context>): Promise<number>;
/**

@@ -180,3 +183,3 @@ * Runs a command and exits the current `process` with the exit code returned by the command.

*/
runExit(input: Command<Context> | Array<string>, context: RunContext<Context>): Promise<void>;
runExit(input: Command<Context> | Array<string>, context: RunContext<BaseContext, Context>): Promise<void>;
suggest(input: Array<string>, partial: boolean): string[][];

@@ -217,3 +220,3 @@ definitions({ colored }?: {

};
protected format(colored?: boolean): ColorFormat;
protected format(colored: boolean | undefined): ColorFormat;
}

@@ -7,2 +7,3 @@ 'use strict';

var Command = require('./Command.js');
var tty = require('tty');
var core = require('../core.js');

@@ -12,11 +13,15 @@ var format = require('../format.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty);
const errorCommandSymbol = Symbol(`clipanion/errorCommand`);
function getDefaultColorSettings() {
function getDefaultColorDepth() {
if (process.env.FORCE_COLOR === `0`)
return false;
return 1;
if (process.env.FORCE_COLOR === `1`)
return true;
return 8;
if (typeof process.stdout !== `undefined` && process.stdout.isTTY)
return true;
return false;
return 8;
return 1;
}

@@ -27,3 +32,3 @@ /**

class Cli {
constructor({ binaryLabel, binaryName: binaryNameOpt = `...`, binaryVersion, enableCapture = false, enableColors = getDefaultColorSettings() } = {}) {
constructor({ binaryLabel, binaryName: binaryNameOpt = `...`, binaryVersion, enableCapture = false, enableColors } = {}) {
this.registrations = new Map();

@@ -105,2 +110,3 @@ this.builder = new core.CliBuilder({ binaryName: binaryNameOpt });

async run(input, userContext) {
var _a;
let command;

@@ -111,2 +117,3 @@ const context = {

};
const colored = (_a = this.enableColors) !== null && _a !== void 0 ? _a : context.colorDepth > 1;
if (!Array.isArray(input)) {

@@ -120,3 +127,3 @@ command = input;

catch (error) {
context.stdout.write(this.error(error));
context.stdout.write(this.error(error, { colored }));
return 1;

@@ -126,3 +133,3 @@ }

if (command.help) {
context.stdout.write(this.usage(command, { detailed: true }));
context.stdout.write(this.usage(command, { colored, detailed: true }));
return 0;

@@ -151,3 +158,3 @@ }

catch (error) {
context.stdout.write(this.error(error, { command }));
context.stdout.write(this.error(error, { colored, command }));
return 1;

@@ -365,4 +372,5 @@ }

}
format(colored = this.enableColors) {
return colored ? format.richFormat : format.textFormat;
format(colored) {
var _a;
return ((_a = colored !== null && colored !== void 0 ? colored : this.enableColors) !== null && _a !== void 0 ? _a : Cli.defaultContext.colorDepth > 1) ? format.richFormat : format.textFormat;
}

@@ -379,2 +387,5 @@ }

stderr: process.stderr,
colorDepth: `getColorDepth` in tty__default['default'].WriteStream.prototype
? tty__default['default'].WriteStream.prototype.getColorDepth()
: getDefaultColorDepth(),
};

@@ -381,0 +392,0 @@ let gContextStorage;

export { Command } from './Command';
export { BaseContext, Cli, CliOptions } from './Cli';
export { BaseContext, Cli, RunContext, CliOptions } from './Cli';
export { CommandClass, Usage, Definition } from './Command';

@@ -4,0 +4,0 @@ export { UsageError, ErrorMeta, ErrorWithMeta } from '../errors';

@@ -1,10 +0,5 @@

/// <reference types="node" />
import { Readable, Writable } from 'stream';
import * as t from 'typanion';
import { Command } from '../advanced';
declare type Context = {
import { Command, BaseContext } from '../advanced';
declare type Context = BaseContext & {
cwd: string;
stdin: Readable;
stdout: Writable;
stderr: Writable;
};

@@ -11,0 +6,0 @@ export default class YarnAdd extends Command<Context> {

{
"name": "clipanion",
"version": "3.1.0",
"version": "3.2.0-rc.1",
"main": "lib/advanced/index",

@@ -5,0 +5,0 @@ "license": "MIT",

Sorry, the diff of this file is not supported yet

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