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

@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.0.3 to 1.0.4

14

dist/oclif-utils.js

@@ -5,6 +5,8 @@ "use strict";

const tslib_1 = require("tslib");
const fs = tslib_1.__importStar(require("fs-extra"));
const Config = tslib_1.__importStar(require("@oclif/config"));
/* eslint-disable max-depth */
const fs = (0, tslib_1.__importStar)(require("fs-extra"));
const Config = (0, tslib_1.__importStar)(require("@oclif/config"));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const plugin_help_1 = require("@oclif/plugin-help");
const Parser = tslib_1.__importStar(require("@oclif/parser"));
const Parser = (0, tslib_1.__importStar)(require("@oclif/parser"));
function getCommandConfig(commandInstance) {

@@ -35,2 +37,3 @@ const cmd = Config.Command.toCached(commandInstance.ctor);

};
// eslint-disable-next-line unicorn/no-static-only-class
class OclifUtils {

@@ -105,5 +108,6 @@ static getCommandConfig(commandInstance) {

if (typeof flagValue !== 'boolean') {
// eslint-disable-next-line max-depth
if (Array.isArray(flagValue)) {
flagValue.forEach(value => args.push(`${quoteIfNeeded(value)}`));
for (const value of flagValue) {
args.push(`${quoteIfNeeded(value)}`);
}
}

@@ -110,0 +114,0 @@ else {

{
"name": "@handy-common-utils/oclif-utils",
"version": "1.0.3",
"version": "1.0.4",
"description": "oclif related utilities",

@@ -22,9 +22,8 @@ "scripts": {

"@oclif/config": "^1.17.0",
"@oclif/plugin-help": "^3.2.0",
"@oclif/plugin-help": "^3.2.3",
"fs-extra": "^9.0.1"
},
"devDependencies": {
"@handy-common-utils/dev-dependencies": "^1.0.12",
"@types/fs-extra": "^8.1.1",
"es-check": "^5.1.2"
"@handy-common-utils/dev-dependencies": "^1.0.19",
"@types/fs-extra": "^8.1.1"
},

@@ -31,0 +30,0 @@ "publishConfig": {

@@ -5,2 +5,11 @@ # @handy-common-utils/oclif-utils

## Features
With this utility library, you will be able to:
* Make type information of `options.args` available
* Update README.md file by `./bin/run --update-readme.md` for inserting properly formated CLI manual information
* Prepend command line name to the examples
* Reconstruct the full command line as a string
## How to use

@@ -17,3 +26,4 @@

```javascript
import { OclifUtils } from '@handy-common-utils/oclif-utils';
import { Command, flags } from '@oclif/command';
import { CommandArgs, CommandFlags, CommandOptions, OclifUtils } from '@handy-common-utils/oclif-utils';

@@ -30,5 +40,11 @@ class AwsServerlessDataflow extends Command {

'update-readme.md': flags.boolean({ hidden: true, description: 'For developers only, don\'t use' }),
debug: flags.boolean({ char: 'd', name: 'debug' }),
// ... other code ...
}
static args = [
{ name: 'path' as const, default: 'dataflow', description: 'path for putting generated website files' },
// ^----- this is needed for the "path" property of options.args to be known to the compiler
];
static examples = [

@@ -43,3 +59,3 @@ '^ -r ap-southeast-2 -s',

protected async init() {
protected async init(): Promise<any> {
OclifUtils.prependCliToExamples(this); // "^" at the beginning of the examples will be replaced by the actual command

@@ -49,3 +65,3 @@ return super.init();

async run(argv?: string[]) {
async run(argv?: string[]): Promise<void> {
const options = this.parse<CommandFlags<typeof AwsServerlessDataflow>, CommandArgs<typeof AwsServerlessDataflow>>(AwsServerlessDataflow, argv);

@@ -57,4 +73,9 @@ if (options.flags['update-readme.md']) {

// This would be helpful if a complex command line needs to be shared
console.log(`Command line: ${OclifUtils.reconstructedcommandLine(this, options)}`);
if (options.flags.debug) {
console.log(`Command line: ${OclifUtils.reconstructCommandLine(this, options)}`);
}
// Now the compiler knows that options.args has a property named "path"
console.log(options.args.path);
// You can add this in the scripts section of your package.json: "preversion": "./bin/run --update-readme.md && git add README.md"

@@ -65,3 +86,3 @@

}
export = AwsServerlessDataflo
export = AwsServerlessDataflow
```

@@ -81,38 +102,31 @@

**[@handy-common-utils/oclif-utils](#readmemd)**
@handy-common-utils/oclif-utils
> Globals
## @handy-common-utils/oclif-utils
### Index
### Table of contents
#### Classes
* [OclifUtils](#classesoclifutilsmd)
* [SingleCommandHelp](#classessinglecommandhelpmd)
- [OclifUtils](#classesoclifutilsmd)
#### Interfaces
* [OclifHelpContent](#interfacesoclifhelpcontentmd)
- [OclifHelpContent](#interfacesoclifhelpcontentmd)
#### Type aliases
* [CommandArgNames](#commandargnames)
* [CommandArgs](#commandargs)
* [CommandFlags](#commandflags)
* [CommandOptions](#commandoptions)
- [CommandArgNames](#commandargnames)
- [CommandArgs](#commandargs)
- [CommandFlags](#commandflags)
- [CommandOptions](#commandoptions)
#### Variables
* [generateHelpText](#generatehelptext)
* [injectHelpTextIntoReadmeMd](#injecthelptextintoreadmemd)
* [parseCommandLine](#parsecommandline)
* [prependCliToExamples](#prependclitoexamples)
* [reconstructCommandLine](#reconstructcommandline)
#### Functions
* [getCommandConfig](#getcommandconfig)
* [quoteIfNeeded](#quoteifneeded)
- [generateHelpText](#generatehelptext)
- [getCommandConfig](#getcommandconfig)
- [injectHelpTextIntoReadmeMd](#injecthelptextintoreadmemd)
- [parseCommandLine](#parsecommandline)
- [prependCliToExamples](#prependclitoexamples)
- [reconstructCommandLine](#reconstructcommandline)

@@ -123,9 +137,9 @@ ### Type aliases

Ƭ **CommandArgNames**\<T>: T *extends* { name: *infer* A }[] ? A : never
Ƭ **CommandArgNames**<`T`\>: `T` extends { `name`: infer A }[] ? `A` : `never`
##### Type parameters:
##### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |

@@ -136,9 +150,9 @@ ___

Ƭ **CommandArgs**\<T>: {}
Ƭ **CommandArgs**<`T`\>: { [x in CommandArgNames<T["args"]\>]: string}
##### Type parameters:
##### Type parameters
Name | Type |
------ | ------ |
`T` | { args: Array\<{ name: string }> } |
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |

@@ -149,9 +163,9 @@ ___

Ƭ **CommandFlags**\<T>: T *extends* Parser.Input\<*infer* F> ? F : never
Ƭ **CommandFlags**<`T`\>: `T` extends `Parser.Input`<infer F\> ? `F` : `never`
##### Type parameters:
##### Type parameters
Name |
------ |
`T` |
| Name |
| :------ |
| `T` |

@@ -162,252 +176,144 @@ ___

Ƭ **CommandOptions**\<T>: Parser.Output\<[CommandFlags](#commandflags)\<T>, [CommandArgs](#commandargs)\<T>>
Ƭ **CommandOptions**<`T`\>: `Parser.Output`<[`CommandFlags`](#commandflags)<`T`\>, [`CommandArgs`](#commandargs)<`T`\>\>
##### Type parameters:
##### Type parameters
Name | Type |
------ | ------ |
`T` | { args: Array\<{ name: string }> } |
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
### Variables
### Functions
#### generateHelpText
• `Const` **generateHelpText**: [generateHelpText](#generatehelptext) = OclifUtils.generateHelpText
▸ `Const` **generateHelpText**(`commandInstance`, `options?`): `string`
___
##### Parameters
#### injectHelpTextIntoReadmeMd
| Name | Type |
| :------ | :------ |
| `commandInstance` | `default` |
| `options?` | `Partial`<`HelpOptions`\> |
• `Const` **injectHelpTextIntoReadmeMd**: [injectHelpTextIntoReadmeMd](#injecthelptextintoreadmemd) = OclifUtils.injectHelpTextIntoReadmeMd
##### Returns
___
`string`
#### parseCommandLine
• `Const` **parseCommandLine**: [parseCommandLine](#parsecommandline) = OclifUtils.parseCommandLine
___
#### prependCliToExamples
#### getCommandConfig
• `Const` **prependCliToExamples**: [prependCliToExamples](#prependclitoexamples) = OclifUtils.prependCliToExamples
▸ **getCommandConfig**(`commandInstance`): `Config.Command`
___
##### Parameters
#### reconstructCommandLine
| Name | Type |
| :------ | :------ |
| `commandInstance` | `Command` |
• `Const` **reconstructCommandLine**: [reconstructCommandLine](#reconstructcommandline) = OclifUtils.reconstructCommandLine
##### Returns
### Functions
`Config.Command`
#### getCommandConfig
▸ **getCommandConfig**(`commandInstance`: Command): Command
##### Parameters:
Name | Type |
------ | ------ |
`commandInstance` | Command |
**Returns:** Command
___
#### quoteIfNeeded
#### injectHelpTextIntoReadmeMd
▸ `Const`**quoteIfNeeded**(`text`: any): string
▸ `Const` **injectHelpTextIntoReadmeMd**(`commandInstance`, `options?`): `Promise`<`void`\>
##### Parameters:
##### Parameters
Name | Type |
------ | ------ |
`text` | any |
| Name | Type |
| :------ | :------ |
| `commandInstance` | `default` |
| `options?` | `Partial`<`HelpOptions`\> |
**Returns:** string
##### Returns
## Classes
`Promise`<`void`\>
<a name="classesoclifutilsmd"></a>
**[@handy-common-utils/oclif-utils](#readmemd)**
> [Globals](#readmemd) / OclifUtils
### Class: OclifUtils
#### Hierarchy
* **OclifUtils**
#### Index
##### Methods
* [generateHelpText](#generatehelptext)
* [getCommandConfig](#getcommandconfig)
* [injectHelpTextIntoReadmeMd](#injecthelptextintoreadmemd)
* [parseCommandLine](#parsecommandline)
* [prependCliToExamples](#prependclitoexamples)
* [reconstructCommandLine](#reconstructcommandline)
#### Methods
##### generateHelpText
▸ `Static` **generateHelpText**(`commandInstance`: Command, `options?`: Partial\<HelpOptions>): string
Generate formatted text content of help to a command
###### Parameters:
Name | Type | Description |
------ | ------ | ------ |
`commandInstance` | Command | instance of the Command |
`options?` | Partial\<HelpOptions> | format options |
**Returns:** string
help content
___
##### getCommandConfig
#### parseCommandLine
▸ `Static` **getCommandConfig**(`commandInstance`: Command): Command
▸ `Const` **parseCommandLine**<`T`\>(`commandInstance`): [`CommandOptions`](#commandoptions)<`T`\>
###### Parameters:
##### Type parameters
Name | Type |
------ | ------ |
`commandInstance` | Command |
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
**Returns:** Command
##### Parameters
___
| Name | Type |
| :------ | :------ |
| `commandInstance` | `InstanceType`<`T`\> |
##### injectHelpTextIntoReadmeMd
##### Returns
▸ `Static` **injectHelpTextIntoReadmeMd**(`commandInstance`: Command, `options?`: Partial\<HelpOptions>): Promise\<void>
[`CommandOptions`](#commandoptions)<`T`\>
###### Parameters:
Name | Type |
------ | ------ |
`commandInstance` | Command |
`options?` | Partial\<HelpOptions> |
**Returns:** Promise\<void>
___
##### parseCommandLine
#### prependCliToExamples
▸ `Static` **parseCommandLine**\<T>(`commandInstance`: InstanceType\<T>): [CommandOptions](#commandoptions)\<T>
▸ `Const` **prependCliToExamples**(`commandInstance`): `void`
###### Type parameters:
##### Parameters
Name | Type |
------ | ------ |
`T` | { constructor: (...args: any) => any ; args: Array\<{ name: string }> } |
| Name | Type |
| :------ | :------ |
| `commandInstance` | `default` |
###### Parameters:
##### Returns
Name | Type |
------ | ------ |
`commandInstance` | InstanceType\<T> |
`void`
**Returns:** [CommandOptions](#commandoptions)\<T>
___
##### prependCliToExamples
#### reconstructCommandLine
▸ `Static` **prependCliToExamples**(`commandInstance`: Command): void
▸ `Const` **reconstructCommandLine**<`T`\>(`commandInstance`, `options?`): `string`
Use this function to prepend command line to examples.
This function needs to be called from `init()` function of the Command.
##### Type parameters
###### Parameters:
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
Name | Type | Description |
------ | ------ | ------ |
`commandInstance` | Command | instance of the Command |
##### Parameters
**Returns:** void
| Name | Type |
| :------ | :------ |
| `commandInstance` | `InstanceType`<`T`\> |
| `options?` | [`CommandOptions`](#commandoptions)<`T`\> |
void
##### Returns
___
`string`
##### reconstructCommandLine
## Classes
▸ `Static` **reconstructCommandLine**\<T>(`commandInstance`: InstanceType\<T>, `options?`: [CommandOptions](#commandoptions)\<T>): string
Reconstruct the command line from already parsed options.
<a name="classesoclifutilsmd"></a>
###### Type parameters:
[@handy-common-utils/oclif-utils](#readmemd) / OclifUtils
Name | Type |
------ | ------ |
`T` | { constructor: (...args: any) => any ; args: Array\<{ name: string }> } |
### Class: OclifUtils
###### Parameters:
#### Table of contents
Name | Type | Description |
------ | ------ | ------ |
`commandInstance` | InstanceType\<T> | When calling from the subclass of `Command`, just pass `this` |
`options?` | [CommandOptions](#commandoptions)\<T> | already parsed options |
**Returns:** string
the command line string corresponding to the parsed options
<a name="classessinglecommandhelpmd"></a>
**[@handy-common-utils/oclif-utils](#readmemd)**
> [Globals](#readmemd) / SingleCommandHelp
### Class: SingleCommandHelp
#### Hierarchy
* Help
↳ **SingleCommandHelp**
#### Index
##### Constructors
* [constructor](#constructor)
- [constructor](#constructor)
##### Properties
* [commandInstance](#commandinstance)
* [config](#config)
* [opts](#opts)
* [render](#render)
##### Accessors
* [sortedCommands](#sortedcommands)
* [sortedTopics](#sortedtopics)
##### Methods
* [command](#command)
* [formatCommand](#formatcommand)
* [formatCommands](#formatcommands)
* [formatRoot](#formatroot)
* [formatTopic](#formattopic)
* [formatTopics](#formattopics)
* [generateHelpText](#generatehelptext)
* [showCommandHelp](#showcommandhelp)
* [showHelp](#showhelp)
* [showRootHelp](#showroothelp)
* [showTopicHelp](#showtopichelp)
- [generateHelpText](#generatehelptext)
- [getCommandConfig](#getcommandconfig)
- [injectHelpTextIntoReadmeMd](#injecthelptextintoreadmemd)
- [parseCommandLine](#parsecommandline)
- [prependCliToExamples](#prependclitoexamples)
- [reconstructCommandLine](#reconstructcommandline)

@@ -418,229 +324,128 @@ #### Constructors

\+ **new SingleCommandHelp**(`commandInstance`: Command, `options?`: Partial\<HelpOptions>): [SingleCommandHelp](#classessinglecommandhelpmd)
• **new OclifUtils**()
*Overrides void*
###### Parameters:
Name | Type |
------ | ------ |
`commandInstance` | Command |
`options?` | Partial\<HelpOptions> |
**Returns:** [SingleCommandHelp](#classessinglecommandhelpmd)
#### Properties
##### commandInstance
• `Protected` **commandInstance**: Command
___
##### config
• `Protected` **config**: IConfig
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[config](#config)*
___
##### opts
• `Protected` **opts**: HelpOptions
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[opts](#opts)*
___
##### render
• **render**: (input: string) => string
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[render](#render)*
#### Accessors
##### sortedCommands
• `Protected`get **sortedCommands**(): Plugin[]
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[sortedCommands](#sortedcommands)*
**Returns:** Plugin[]
___
##### sortedTopics
• `Protected`get **sortedTopics**(): Topic[]
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[sortedTopics](#sortedtopics)*
**Returns:** Topic[]
#### Methods
##### command
##### generateHelpText
▸ `Protected`**command**(`command`: Command): string
▸ `Static` **generateHelpText**(`commandInstance`, `options?`): `string`
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[command](#command)*
Generate formatted text content of help to a command
**`deprecated`** used for readme generation
###### Parameters
###### Parameters:
| Name | Type | Description |
| :------ | :------ | :------ |
| `commandInstance` | `default` | instance of the Command |
| `options?` | `Partial`<`HelpOptions`\> | format options |
Name | Type | Description |
------ | ------ | ------ |
`command` | Command | The command to generate readme help for |
###### Returns
**Returns:** string
`string`
the readme help string for the given command
help content
___
##### formatCommand
##### getCommandConfig
▸ `Protected`**formatCommand**(`command`: Command): string
▸ `Static` **getCommandConfig**(`commandInstance`): `Command`
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[formatCommand](#formatcommand)*
###### Parameters
###### Parameters:
| Name | Type |
| :------ | :------ |
| `commandInstance` | `default` |
Name | Type |
------ | ------ |
`command` | Command |
###### Returns
**Returns:** string
`Command`
___
##### formatCommands
##### injectHelpTextIntoReadmeMd
▸ `Protected`**formatCommands**(`commands`: Command[]): string
▸ `Static` **injectHelpTextIntoReadmeMd**(`commandInstance`, `options?`): `Promise`<`void`\>
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[formatCommands](#formatcommands)*
###### Parameters
###### Parameters:
| Name | Type |
| :------ | :------ |
| `commandInstance` | `default` |
| `options?` | `Partial`<`HelpOptions`\> |
Name | Type |
------ | ------ |
`commands` | Command[] |
###### Returns
**Returns:** string
`Promise`<`void`\>
___
##### formatRoot
##### parseCommandLine
▸ `Protected`**formatRoot**(): string
▸ `Static` **parseCommandLine**<`T`\>(`commandInstance`): [`CommandOptions`](#commandoptions)<`T`\>
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[formatRoot](#formatroot)*
###### Type parameters
**Returns:** string
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
___
###### Parameters
##### formatTopic
| Name | Type |
| :------ | :------ |
| `commandInstance` | `InstanceType`<`T`\> |
▸ `Protected`**formatTopic**(`topic`: Topic): string
###### Returns
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[formatTopic](#formattopic)*
[`CommandOptions`](#commandoptions)<`T`\>
###### Parameters:
Name | Type |
------ | ------ |
`topic` | Topic |
**Returns:** string
___
##### formatTopics
##### prependCliToExamples
▸ `Protected`**formatTopics**(`topics`: Topic[]): string
▸ `Static` **prependCliToExamples**(`commandInstance`): `void`
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[formatTopics](#formattopics)*
Use this function to prepend command line to examples.
This function needs to be called from `init()` function of the Command.
###### Parameters:
###### Parameters
Name | Type |
------ | ------ |
`topics` | Topic[] |
| Name | Type | Description |
| :------ | :------ | :------ |
| `commandInstance` | `default` | instance of the Command |
**Returns:** string
###### Returns
___
`void`
##### generateHelpText
void
▸ **generateHelpText**(): string
**Returns:** string
___
##### showCommandHelp
##### reconstructCommandLine
▸ **showCommandHelp**(`command`: Command): void
▸ `Static` **reconstructCommandLine**<`T`\>(`commandInstance`, `options?`): `string`
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[showCommandHelp](#showcommandhelp)*
Reconstruct the command line from already parsed options.
*Overrides void*
###### Type parameters
###### Parameters:
| Name | Type |
| :------ | :------ |
| `T` | extends `Object` |
Name | Type |
------ | ------ |
`command` | Command |
###### Parameters
**Returns:** void
| Name | Type | Description |
| :------ | :------ | :------ |
| `commandInstance` | `InstanceType`<`T`\> | When calling from the subclass of `Command`, just pass `this` |
| `options?` | [`CommandOptions`](#commandoptions)<`T`\> | already parsed options |
___
###### Returns
##### showHelp
`string`
▸ **showHelp**(`argv`: string[]): void
the command line string corresponding to the parsed options
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[showHelp](#showhelp)*
*Overrides void*
###### Parameters:
Name | Type |
------ | ------ |
`argv` | string[] |
**Returns:** void
___
##### showRootHelp
▸ `Protected`**showRootHelp**(): void
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[showRootHelp](#showroothelp)*
**Returns:** void
___
##### showTopicHelp
▸ `Protected`**showTopicHelp**(`topic`: Topic): void
*Inherited from [SingleCommandHelp](#classessinglecommandhelpmd).[showTopicHelp](#showtopichelp)*
###### Parameters:
Name | Type |
------ | ------ |
`topic` | Topic |
**Returns:** void
## Interfaces

@@ -651,22 +456,16 @@

**[@handy-common-utils/oclif-utils](#readmemd)**
[@handy-common-utils/oclif-utils](#readmemd) / OclifHelpContent
> [Globals](#readmemd) / OclifHelpContent
### Interface: OclifHelpContent
#### Hierarchy
#### Table of contents
* **OclifHelpContent**
#### Index
##### Properties
* [aliases](#aliases)
* [args](#args)
* [description](#description)
* [examples](#examples)
* [flags](#flags)
* [usage](#usage)
- [aliases](#aliases)
- [args](#args)
- [description](#description)
- [examples](#examples)
- [flags](#flags)
- [usage](#usage)

@@ -677,3 +476,3 @@ #### Properties

• `Optional` **aliases**: undefined \| string
• `Optional` **aliases**: `string`

@@ -684,3 +483,3 @@ ___

• `Optional` **args**: undefined \| string
• `Optional` **args**: `string`

@@ -691,3 +490,3 @@ ___

• `Optional` **description**: undefined \| string
• `Optional` **description**: `string`

@@ -698,3 +497,3 @@ ___

• `Optional` **examples**: undefined \| string
• `Optional` **examples**: `string`

@@ -705,3 +504,3 @@ ___

• `Optional` **flags**: undefined \| string
• `Optional` **flags**: `string`

@@ -712,3 +511,3 @@ ___

• `Optional` **usage**: undefined \| string
• `Optional` **usage**: `string`
<!-- API end -->

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