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

oclif related utilities

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by13.33%
Maintainers
1
Weekly downloads
 
Created
Source

@handy-common-utils/oclif-utils

oclif (https://oclif.io/) related utilities

How to use

First add it as a dependency:

npm install @handy-common-utils/oclif-utils

Then you can use it in the code:

import { OclifUtils } from '@handy-common-utils/oclif-utils';

class AwsServerlessDataflow extends Command {
  // You can use "typeof AwsServerlessDataflow.Options" in other places to refer to the type
  static Options: CommandOptions<typeof AwsServerlessDataflow>

  // ... other code ...

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

  static examples = [
    '^ -r ap-southeast-2 -s',
    `^ -r ap-southeast-2 -s -i '*boi*' -i '*datahub*' \\
      -x '*jameshu*' -c`,
    `^ -r ap-southeast-2 -s -i '*lr-*' \\
      -i '*lead*' -x '*slack*' -x '*lead-prioritization*' \\
      -x '*lead-scor*' -x '*LeadCapture*' -c`,
  ];

  protected async init() {
    OclifUtils.prependCliToExamples(this);  // "^" at the beginning of the examples will be replaced by the actual command
    return super.init();
  }

  async run(argv?: string[]) {
    const options = this.parse<CommandFlags<typeof AwsServerlessDataflow>, CommandArgs<typeof AwsServerlessDataflow>>(AwsServerlessDataflow, argv);
    if (options.flags['update-readme.md']) {
      OclifUtils.injectHelpTextIntoReadmeMd(this); // you need to have <!-- help start -->...<!-- help end --> in your README.md
      return;
    }
    // This would be helpful if a complex command line needs to be shared
    console.log(`Command line: ${OclifUtils.reconstructedcommandLine(this, options)}`);

    // You can add this in the scripts section of your package.json:  "preversion": "./bin/run --update-readme.md && git add README.md"

    // ... other code ...
  }
}
export = AwsServerlessDataflo

You can either import and use the class as shown above, or you can import individual functions directly like below:

import { prependCliToExamples } from '@handy-common-utils/oclif-utils';

API

@handy-common-utils/oclif-utils

Globals

@handy-common-utils/oclif-utils

Index

Classes
Interfaces
Type aliases
Variables
Functions

Type aliases

CommandArgNames

Ƭ CommandArgNames<T>: T extends { name: infer A }[] ? A : never

Type parameters:
Name
T

CommandArgs

Ƭ CommandArgs<T>: {}

Type parameters:
NameType
T{ args: Array<{ name: string }> }

CommandFlags

Ƭ CommandFlags<T>: T extends Parser.Input<infer F> ? F : never

Type parameters:
Name
T

CommandOptions

Ƭ CommandOptions<T>: Parser.Output<CommandFlags<T>, CommandArgs<T>>

Type parameters:
NameType
T{ args: Array<{ name: string }> }

Variables

generateHelpText

Const generateHelpText: generateHelpText = OclifUtils.generateHelpText


injectHelpTextIntoReadmeMd

Const injectHelpTextIntoReadmeMd: injectHelpTextIntoReadmeMd = OclifUtils.injectHelpTextIntoReadmeMd


parseCommandLine

Const parseCommandLine: parseCommandLine = OclifUtils.parseCommandLine


prependCliToExamples

Const prependCliToExamples: prependCliToExamples = OclifUtils.prependCliToExamples


reconstructCommandLine

Const reconstructCommandLine: reconstructCommandLine = OclifUtils.reconstructCommandLine

Functions

getCommandConfig

getCommandConfig(commandInstance: Command): Command

Parameters:
NameType
commandInstanceCommand

Returns: Command


quoteIfNeeded

ConstquoteIfNeeded(text: any): string

Parameters:
NameType
textany

Returns: string

Classes

@handy-common-utils/oclif-utils

Globals / OclifUtils

Class: OclifUtils

Hierarchy
  • OclifUtils
Index
Methods
Methods
generateHelpText

Static generateHelpText(commandInstance: Command, options?: Partial<HelpOptions>): string

Generate formatted text content of help to a command

Parameters:
NameTypeDescription
commandInstanceCommandinstance of the Command
options?Partial<HelpOptions>format options

Returns: string

help content


getCommandConfig

Static getCommandConfig(commandInstance: Command): Command

Parameters:
NameType
commandInstanceCommand

Returns: Command


injectHelpTextIntoReadmeMd

Static injectHelpTextIntoReadmeMd(commandInstance: Command, options?: Partial<HelpOptions>): Promise<void>

Parameters:
NameType
commandInstanceCommand
options?Partial<HelpOptions>

Returns: Promise<void>


parseCommandLine

Static parseCommandLine<T>(commandInstance: InstanceType<T>): CommandOptions<T>

Type parameters:
NameType
T{ constructor: (...args: any) => any ; args: Array<{ name: string }> }
Parameters:
NameType
commandInstanceInstanceType<T>

Returns: CommandOptions<T>


prependCliToExamples

Static prependCliToExamples(commandInstance: Command): void

Use this function to prepend command line to examples. This function needs to be called from init() function of the Command.

Parameters:
NameTypeDescription
commandInstanceCommandinstance of the Command

Returns: void

void


reconstructCommandLine

Static reconstructCommandLine<T>(commandInstance: InstanceType<T>, options?: CommandOptions<T>): string

Reconstruct the command line from already parsed options.

Type parameters:
NameType
T{ constructor: (...args: any) => any ; args: Array<{ name: string }> }
Parameters:
NameTypeDescription
commandInstanceInstanceType<T>When calling from the subclass of Command, just pass this
options?CommandOptions<T>already parsed options

Returns: string

the command line string corresponding to the parsed options

@handy-common-utils/oclif-utils

Globals / SingleCommandHelp

Class: SingleCommandHelp

Hierarchy
  • Help

    SingleCommandHelp

Index
Constructors
Properties
Accessors
Methods
Constructors
constructor

+ new SingleCommandHelp(commandInstance: Command, options?: Partial<HelpOptions>): SingleCommandHelp

Overrides void

Parameters:
NameType
commandInstanceCommand
options?Partial<HelpOptions>

Returns: SingleCommandHelp

Properties
commandInstance

Protected commandInstance: Command


config

Protected config: IConfig

Inherited from SingleCommandHelp.config


opts

Protected opts: HelpOptions

Inherited from SingleCommandHelp.opts


render

render: (input: string) => string

Inherited from SingleCommandHelp.render

Accessors
sortedCommands

Protectedget sortedCommands(): Plugin[]

Inherited from SingleCommandHelp.sortedCommands

Returns: Plugin[]


sortedTopics

Protectedget sortedTopics(): Topic[]

Inherited from SingleCommandHelp.sortedTopics

Returns: Topic[]

Methods
command

Protectedcommand(command: Command): string

Inherited from SingleCommandHelp.command

deprecated used for readme generation

Parameters:
NameTypeDescription
commandCommandThe command to generate readme help for

Returns: string

the readme help string for the given command


formatCommand

ProtectedformatCommand(command: Command): string

Inherited from SingleCommandHelp.formatCommand

Parameters:
NameType
commandCommand

Returns: string


formatCommands

ProtectedformatCommands(commands: Command[]): string

Inherited from SingleCommandHelp.formatCommands

Parameters:
NameType
commandsCommand[]

Returns: string


formatRoot

ProtectedformatRoot(): string

Inherited from SingleCommandHelp.formatRoot

Returns: string


formatTopic

ProtectedformatTopic(topic: Topic): string

Inherited from SingleCommandHelp.formatTopic

Parameters:
NameType
topicTopic

Returns: string


formatTopics

ProtectedformatTopics(topics: Topic[]): string

Inherited from SingleCommandHelp.formatTopics

Parameters:
NameType
topicsTopic[]

Returns: string


generateHelpText

generateHelpText(): string

Returns: string


showCommandHelp

showCommandHelp(command: Command): void

Inherited from SingleCommandHelp.showCommandHelp

Overrides void

Parameters:
NameType
commandCommand

Returns: void


showHelp

showHelp(argv: string[]): void

Inherited from SingleCommandHelp.showHelp

Overrides void

Parameters:
NameType
argvstring[]

Returns: void


showRootHelp

ProtectedshowRootHelp(): void

Inherited from SingleCommandHelp.showRootHelp

Returns: void


showTopicHelp

ProtectedshowTopicHelp(topic: Topic): void

Inherited from SingleCommandHelp.showTopicHelp

Parameters:
NameType
topicTopic

Returns: void

Interfaces

@handy-common-utils/oclif-utils

Globals / OclifHelpContent

Interface: OclifHelpContent

Hierarchy
  • OclifHelpContent
Index
Properties
Properties
aliases

Optional aliases: undefined | string


args

Optional args: undefined | string


description

Optional description: undefined | string


examples

Optional examples: undefined | string


flags

Optional flags: undefined | string


usage

Optional usage: undefined | string

Keywords

FAQs

Package last updated on 14 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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