Socket
Socket
Sign inDemoInstall

@handy-common-utils/oclif-utils

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@handy-common-utils/oclif-utils - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

4

dist/index.d.ts

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

/**
* @ignore
* @module
*/
export * from './cli-console';
export * from './oclif-utils';
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/**
* @ignore
* @module
*/
tslib_1.__exportStar(require("./cli-console"), exports);
tslib_1.__exportStar(require("./oclif-utils"), exports);

53

dist/oclif-utils.d.ts

@@ -1,21 +0,4 @@

import * as Config from '@oclif/config';
import { Command } from '@oclif/command';
import { Help } from '@oclif/core';
import * as Parser from '@oclif/parser';
export declare function getCommandConfig(commandInstance: Command): Config.Command;
declare class SingleCommandHelp extends Help {
protected commandInstance: Command;
constructor(commandInstance: Command, options?: ConstructorParameters<typeof Help>[1]);
generateHelpText(): string;
}
export interface OclifHelpContent {
usage?: string;
args?: string;
flags?: string;
description?: string;
aliases?: string;
examples?: string;
}
import { Command, Interfaces } from '@oclif/core';
export declare class OclifUtils {
static getCommandConfig(commandInstance: Command): Config.Command;
static getCommandConfig(commandInstance: Command): Promise<Interfaces.Command>;
/**

@@ -34,14 +17,8 @@ * Use this function to prepend command line to examples.

*/
static generateHelpText(commandInstance: Command, options?: ConstructorParameters<typeof SingleCommandHelp>[1]): string;
static injectHelpTextIntoReadmeMd(commandInstance: Command, options?: ConstructorParameters<typeof SingleCommandHelp>[1]): Promise<void>;
static parseCommandLine<T extends {
args: Array<{
name: string;
}>;
new (...args: any): any;
}>(commandInstance: InstanceType<T>): CommandOptions<T>;
static generateHelpText(commandInstance: Command, options?: Interfaces.HelpOptions): Promise<string>;
static injectHelpTextIntoReadmeMd(commandInstance: Command, options?: Interfaces.HelpOptions): Promise<void>;
/**
* Reconstruct the command line from already parsed options.
* @param commandInstance When calling from the subclass of `Command`, just pass `this`
* @param options already parsed options
* @param options Already parsed options. It can be got with `const options = await OclifUtils.parseCommandLine(commandInstance);`
* @returns the command line string corresponding to the parsed options

@@ -54,19 +31,15 @@ */

new (...args: any): any;
}>(commandInstance: InstanceType<T>, options?: CommandOptions<T>): string;
}>(commandInstance: InstanceType<T>, options: CommandOptions<T>): string;
}
export declare const getCommandConfig: typeof OclifUtils.getCommandConfig;
export declare const prependCliToExamples: typeof OclifUtils.prependCliToExamples;
export declare const generateHelpText: typeof OclifUtils.generateHelpText;
export declare const injectHelpTextIntoReadmeMd: typeof OclifUtils.injectHelpTextIntoReadmeMd;
export declare const parseCommandLine: typeof OclifUtils.parseCommandLine;
export declare const reconstructCommandLine: typeof OclifUtils.reconstructCommandLine;
/**
* Get the flag object type from flags configuration type
*/
export declare type Flags<T> = T extends Parser.flags.Input<infer F> ? F : never;
export declare type CommandFlags<T> = T extends Parser.Input<infer F> ? F : never;
export declare type CommandArgNames<T> = T extends {
declare type CommandFlags<T> = T extends Interfaces.Input<infer F> ? F : never;
declare type CommandArgNames<T> = T extends {
name: infer A;
}[] ? A : never;
export declare type CommandArgs<T extends {
args: Array<{
declare type CommandArgs<T extends {
args?: Array<{
name: string;

@@ -78,7 +51,7 @@ }>;

export declare type CommandOptions<T extends {
args: Array<{
args?: Array<{
name: string;
}>;
}> = Parser.Output<CommandFlags<T>, CommandArgs<T>>;
}> = Interfaces.ParserOutput<CommandFlags<T>, CommandArgs<T>>;
export {};
//# sourceMappingURL=oclif-utils.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.reconstructCommandLine = exports.parseCommandLine = exports.injectHelpTextIntoReadmeMd = exports.generateHelpText = exports.prependCliToExamples = exports.OclifUtils = exports.getCommandConfig = void 0;
exports.reconstructCommandLine = exports.injectHelpTextIntoReadmeMd = exports.generateHelpText = exports.prependCliToExamples = exports.getCommandConfig = exports.OclifUtils = void 0;
const tslib_1 = require("tslib");
/* eslint-disable no-warning-comments */
const fs = tslib_1.__importStar(require("fs-extra"));
const Config = tslib_1.__importStar(require("@oclif/config"));
const core_1 = require("@oclif/core");
const Parser = tslib_1.__importStar(require("@oclif/parser"));
function getCommandConfig(commandInstance) {
const cmd = Config.Command.toCached(commandInstance.ctor);
if (cmd.id === undefined) {
cmd.id = '';
}
return cmd;
}
exports.getCommandConfig = getCommandConfig;
class SingleCommandHelp extends core_1.Help {
class HelpHelper extends core_1.Help {
constructor(commandInstance, options) {
// TODO: casting to any is risky
super(commandInstance.config, options);
this.commandInstance = commandInstance;
}
generateHelpText() {
const cmd = getCommandConfig(this.commandInstance);
// TODO: casting to any is risky
async generateHelpText() {
const cmd = await (0, exports.getCommandConfig)(this.commandInstance);
const helpText = this.formatCommand(cmd);

@@ -38,4 +25,8 @@ return helpText;

class OclifUtils {
static getCommandConfig(commandInstance) {
return getCommandConfig(commandInstance);
static async getCommandConfig(commandInstance) {
const cmd = await (0, core_1.toCached)(commandInstance.ctor);
if (cmd.id === undefined) {
cmd.id = '';
}
return cmd;
}

@@ -51,3 +42,12 @@ /**

if (Array.isArray(cmd.examples)) { // so that we don't have to hard code command name in the examples
cmd.examples = cmd.examples.map(s => s.startsWith('^ ') ? s.replace('^', commandInstance.config.bin) : s);
const prepend = (s) => (s && s.startsWith('^ ')) ? s.replace('^', commandInstance.config.bin) : s;
// eslint-disable-next-line unicorn/no-array-for-each
cmd.examples.forEach((example, index, examples) => {
if (typeof example === 'string') {
examples[index] = prepend(example);
}
else if (example === null || example === void 0 ? void 0 : example.command) {
example.command = prepend(example.command);
}
});
}

@@ -62,7 +62,7 @@ }

static generateHelpText(commandInstance, options) {
const help = new SingleCommandHelp(commandInstance, Object.assign({ stripAnsi: true, maxWidth: 80 }, options));
return help.generateHelpText();
const helper = new HelpHelper(commandInstance, Object.assign({ stripAnsi: true, maxWidth: 80 }, options));
return helper.generateHelpText();
}
static async injectHelpTextIntoReadmeMd(commandInstance, options) {
const helpText = OclifUtils.generateHelpText(commandInstance, Object.assign({ stripAnsi: true, maxWidth: 80 }, options));
const helpText = await OclifUtils.generateHelpText(commandInstance, options);
const helpTextMd = '```\n' + helpText + '\n```\n';

@@ -76,9 +76,6 @@ const fileName = 'README.md';

}
static parseCommandLine(commandInstance) {
return Parser.parse(commandInstance.argv, Object.assign({ context: commandInstance }, commandInstance.ctor));
}
/**
* Reconstruct the command line from already parsed options.
* @param commandInstance When calling from the subclass of `Command`, just pass `this`
* @param options already parsed options
* @param options Already parsed options. It can be got with `const options = await OclifUtils.parseCommandLine(commandInstance);`
* @returns the command line string corresponding to the parsed options

@@ -88,9 +85,6 @@ */

var _a;
if (options === undefined) {
options = OclifUtils.parseCommandLine(commandInstance);
}
const args = new Array();
args.push(commandInstance.config.bin);
if (((_a = options.argv) === null || _a === void 0 ? void 0 : _a.length) > 0) {
args.push(...options.argv.map(x => quoteIfNeeded(x)));
args.push(...options.argv.map((x) => quoteIfNeeded(x)));
}

@@ -119,6 +113,6 @@ if (options.flags) {

exports.OclifUtils = OclifUtils;
exports.getCommandConfig = OclifUtils.getCommandConfig;
exports.prependCliToExamples = OclifUtils.prependCliToExamples;
exports.generateHelpText = OclifUtils.generateHelpText;
exports.injectHelpTextIntoReadmeMd = OclifUtils.injectHelpTextIntoReadmeMd;
exports.parseCommandLine = OclifUtils.parseCommandLine;
exports.reconstructCommandLine = OclifUtils.reconstructCommandLine;
{
"name": "@handy-common-utils/oclif-utils",
"version": "1.1.0",
"version": "1.1.1",
"description": "oclif related utilities",

@@ -20,9 +20,7 @@ "scripts": {

"@handy-common-utils/promise-utils": "^1.2.4",
"@oclif/command": "^1.8.16",
"@oclif/config": "^1.18.3",
"@oclif/plugin-help": "^5.1.12",
"fs-extra": "^9.0.1"
},
"devDependencies": {
"@handy-common-utils/dev-dependencies": "^1.1.0",
"@handy-common-utils/dev-dependencies": "^1.1.1",
"@oclif/core": "^1.6.1",
"@types/fs-extra": "^8.1.1"

@@ -47,3 +45,6 @@ },

"author": "James Hu",
"license": "Apache-2.0"
"license": "Apache-2.0",
"peerDependencies": {
"@oclif/core": "^1.6.1 || ^2"
}
}

@@ -22,3 +22,4 @@ # @handy-common-utils/oclif-utils

If you are using latest versions of oclif components ("@oclif/command": "^1.8.16", "@oclif/config": "^1.18.3", "@oclif/plugin-help": "^5.1.12"),
If you are using latest versions of
[@oclif/core](https://github.com/oclif/core)([introduction](https://oclif.io/blog/2021/03/01/introducing-oclif-core), [migration](https://github.com/oclif/core/blob/main/MIGRATION.md)),
just add latest version of this package as dependency:

@@ -30,3 +31,3 @@

Otherwise if the versions of oclif components you are using are older,
Otherwise if the versions of oclif components you are using are older (that means you are still using @oclif/config, @oclif/command, @oclif/parser),
you need to use the older version of this package:

@@ -42,3 +43,3 @@

```javascript
import { Command, flags } from '@oclif/command';
import { Command, Flags } from '@oclif/core';
import { OclifUtils, cliConsole, cliConsoleWithColour } from '@handy-common-utils/oclif-utils';

@@ -53,6 +54,6 @@

static flags = {
version: flags.version({ char: 'v' }),
help: flags.help({ char: 'h' }),
version: Flags.version({ char: 'v' }),
help: Flags.help({ char: 'h' }),
'update-readme.md': flags.boolean({ hidden: true, description: 'For developers only, don\'t use' }),
debug: flags.boolean({ char: 'd', name: 'debug' }),
debug: Flags.boolean({ char: 'd', name: 'debug' }),
// ... other code ...

@@ -81,3 +82,3 @@ }

async run(): Promise<void> {
const options = OclifUtils.parseCommandLine<typeof AwsServerlessDataflow>(this);
const options = await this.parse() as CommandOptions<typeof AwsServerlessDataflow>; // as typeof AwsServerlessDataflow.Options
if (options.flags['update-readme.md']) {

@@ -120,3 +121,2 @@ OclifUtils.injectHelpTextIntoReadmeMd(this); // you need to have <!-- help start -->...<!-- help end --> in your README.md

- [cli-console](#modulescli_consolemd)
- [index](#modulesindexmd)
- [oclif-utils](#modulesoclif_utilsmd)

@@ -264,3 +264,3 @@

▸ `Static` **generateHelpText**(`commandInstance`, `options?`): `string`
▸ `Static` **generateHelpText**(`commandInstance`, `options?`): `Promise`<`string`\>

@@ -274,7 +274,7 @@ Generate formatted text content of help to a command

| `commandInstance` | `default` | instance of the Command |
| `options?` | `Partial`<`HelpOptions`\> | format options |
| `options?` | `HelpOptions` | format options |
###### Returns
`string`
`Promise`<`string`\>

@@ -287,3 +287,3 @@ help content

▸ `Static` **getCommandConfig**(`commandInstance`): `Command`
▸ `Static` **getCommandConfig**(`commandInstance`): `Promise`<`Command`\>

@@ -298,3 +298,3 @@ ###### Parameters

`Command`
`Promise`<`Command`\>

@@ -312,3 +312,3 @@ ___

| `commandInstance` | `default` |
| `options?` | `Partial`<`HelpOptions`\> |
| `options?` | `HelpOptions` |

@@ -321,24 +321,2 @@ ###### Returns

##### parseCommandLine
▸ `Static` **parseCommandLine**<`T`\>(`commandInstance`): [`CommandOptions`](#commandoptions)<`T`\>
###### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
###### Parameters
| Name | Type |
| :------ | :------ |
| `commandInstance` | `InstanceType`<`T`\> |
###### Returns
[`CommandOptions`](#commandoptions)<`T`\>
___
##### prependCliToExamples

@@ -367,3 +345,3 @@

▸ `Static` **reconstructCommandLine**<`T`\>(`commandInstance`, `options?`): `string`
▸ `Static` **reconstructCommandLine**<`T`\>(`commandInstance`, `options`): `string`

@@ -383,3 +361,3 @@ Reconstruct the command line from already parsed options.

| `commandInstance` | `InstanceType`<`T`\> | When calling from the subclass of `Command`, just pass `this` |
| `options?` | [`CommandOptions`](#commandoptions)<`T`\> | already parsed options |
| `options` | [`CommandOptions`](#commandoptions)<`T`\> | Already parsed options. It can be got with `const options = await OclifUtils.parseCommandLine(commandInstance);` |

@@ -392,23 +370,9 @@ ###### Returns

## Interfaces
## Modules
<a name="interfacesoclif_utilsoclifhelpcontentmd"></a>
<a name="modulescli_consolemd"></a>
### Interface: OclifHelpContent
### Module: cli-console
[oclif-utils](#modulesoclif_utilsmd).OclifHelpContent
#### Properties
| Property | Description |
| --- | --- |
| • `Optional` **aliases**: `string` | |
| • `Optional` **args**: `string` | |
| • `Optional` **description**: `string` | |
| • `Optional` **examples**: `string` | |
| • `Optional` **flags**: `string` | |
| • `Optional` **usage**: `string` | ## Modules<br><br><br><a name="modulescli_consolemd"></a><br><br>### Module: cli-console |
#### Classes

@@ -489,109 +453,2 @@

<a name="modulesindexmd"></a>
### Module: index
#### References
##### CliConsole
Re-exports [CliConsole](#classescli_consolecliconsolemd)
___
##### CommandArgNames
Re-exports [CommandArgNames](#commandargnames)
___
##### CommandArgs
Re-exports [CommandArgs](#commandargs)
___
##### CommandFlags
Re-exports [CommandFlags](#commandflags)
___
##### CommandOptions
Re-exports [CommandOptions](#commandoptions)
___
##### DefaultCliConsole
Re-exports [DefaultCliConsole](#defaultcliconsole)
___
##### Flags
Re-exports [Flags](#flags)
___
##### OclifHelpContent
Re-exports [OclifHelpContent](#interfacesoclif_utilsoclifhelpcontentmd)
___
##### OclifUtils
Re-exports [OclifUtils](#classesoclif_utilsoclifutilsmd)
___
##### cliConsole
Re-exports [cliConsole](#cliconsole)
___
##### cliConsoleWithColour
Re-exports [cliConsoleWithColour](#cliconsolewithcolour)
___
##### generateHelpText
Re-exports [generateHelpText](#generatehelptext)
___
##### getCommandConfig
Re-exports [getCommandConfig](#getcommandconfig)
___
##### injectHelpTextIntoReadmeMd
Re-exports [injectHelpTextIntoReadmeMd](#injecthelptextintoreadmemd)
___
##### parseCommandLine
Re-exports [parseCommandLine](#parsecommandline)
___
##### prependCliToExamples
Re-exports [prependCliToExamples](#prependclitoexamples)
___
##### reconstructCommandLine
Re-exports [reconstructCommandLine](#reconstructcommandline)
<a name="modulesoclif_utilsmd"></a>

@@ -605,47 +462,7 @@

#### Interfaces
- [OclifHelpContent](#interfacesoclif_utilsoclifhelpcontentmd)
#### Type aliases
##### CommandArgNames
Ƭ **CommandArgNames**<`T`\>: `T` extends { `name`: infer A }[] ? `A` : `never`
###### Type parameters
| Name |
| :------ |
| `T` |
___
##### CommandArgs
Ƭ **CommandArgs**<`T`\>: { [x in CommandArgNames<T["args"]\>]: string }
###### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
___
##### CommandFlags
Ƭ **CommandFlags**<`T`\>: `T` extends `Parser.Input`<infer F\> ? `F` : `never`
###### Type parameters
| Name |
| :------ |
| `T` |
___
##### CommandOptions
Ƭ **CommandOptions**<`T`\>: `Parser.Output`<[`CommandFlags`](#commandflags)<`T`\>, [`CommandArgs`](#commandargs)<`T`\>\>
Ƭ **CommandOptions**<`T`\>: `Interfaces.ParserOutput`<`CommandFlags`<`T`\>, `CommandArgs`<`T`\>\>

@@ -658,16 +475,2 @@ ###### Type parameters

___
##### Flags
Ƭ **Flags**<`T`\>: `T` extends `Parser.flags.Input`<infer F\> ? `F` : `never`
Get the flag object type from flags configuration type
###### Type parameters
| Name |
| :------ |
| `T` |
#### Functions

@@ -677,3 +480,3 @@

▸ **generateHelpText**(`commandInstance`, `options?`): `string`
▸ **generateHelpText**(`commandInstance`, `options?`): `Promise`<`string`\>

@@ -685,7 +488,7 @@ ###### Parameters

| `commandInstance` | `default` |
| `options?` | `Partial`<`HelpOptions`\> |
| `options?` | `HelpOptions` |
###### Returns
`string`
`Promise`<`string`\>

@@ -696,3 +499,3 @@ ___

▸ **getCommandConfig**(`commandInstance`): `Config.Command`
▸ **getCommandConfig**(`commandInstance`): `Promise`<`Command`\>

@@ -707,3 +510,3 @@ ###### Parameters

`Config.Command`
`Promise`<`Command`\>

@@ -721,3 +524,3 @@ ___

| `commandInstance` | `default` |
| `options?` | `Partial`<`HelpOptions`\> |
| `options?` | `HelpOptions` |

@@ -730,24 +533,2 @@ ###### Returns

##### parseCommandLine
▸ **parseCommandLine**<`T`\>(`commandInstance`): [`CommandOptions`](#commandoptions)<`T`\>
###### Type parameters
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
###### Parameters
| Name | Type |
| :------ | :------ |
| `commandInstance` | `InstanceType`<`T`\> |
###### Returns
[`CommandOptions`](#commandoptions)<`T`\>
___
##### prependCliToExamples

@@ -771,3 +552,3 @@

▸ **reconstructCommandLine**<`T`\>(`commandInstance`, `options?`): `string`
▸ **reconstructCommandLine**<`T`\>(`commandInstance`, `options`): `string`

@@ -785,3 +566,3 @@ ###### Type parameters

| `commandInstance` | `InstanceType`<`T`\> |
| `options?` | [`CommandOptions`](#commandoptions)<`T`\> |
| `options` | [`CommandOptions`](#commandoptions)<`T`\> |

@@ -788,0 +569,0 @@ ###### Returns

Sorry, the diff of this file is not supported yet

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