@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 {
static Options: CommandOptions<typeof AwsServerlessDataflow>
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' }),
}
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);
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);
return;
}
console.log(`Command line: ${OclifUtils.reconstructedcommandLine(this, options)}`);
}
}
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:
CommandArgs
Ƭ CommandArgs<T>: {}
Type parameters:
Name | Type |
---|
T | { args: Array<{ name: string }> } |
CommandFlags
Ƭ CommandFlags<T>: T extends Parser.Input<infer F> ? F : never
Type parameters:
CommandOptions
Ƭ CommandOptions<T>: Parser.Output<CommandFlags<T>, CommandArgs<T>>
Type parameters:
Name | Type |
---|
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:
Name | Type |
---|
commandInstance | Command |
Returns: Command
quoteIfNeeded
▸ Const
quoteIfNeeded(text
: any): string
Parameters:
Returns: string
Classes
@handy-common-utils/oclif-utils
Globals / OclifUtils
Class: OclifUtils
Hierarchy
Index
Methods
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
▸ Static
getCommandConfig(commandInstance
: Command): Command
Parameters:
Name | Type |
---|
commandInstance | Command |
Returns: Command
injectHelpTextIntoReadmeMd
▸ Static
injectHelpTextIntoReadmeMd(commandInstance
: Command, options?
: Partial<HelpOptions>): Promise<void>
Parameters:
Name | Type |
---|
commandInstance | Command |
options? | Partial<HelpOptions> |
Returns: Promise<void>
parseCommandLine
▸ Static
parseCommandLine<T>(commandInstance
: InstanceType<T>): CommandOptions<T>
Type parameters:
Name | Type |
---|
T | { constructor: (...args: any) => any ; args: Array<{ name: string }> } |
Parameters:
Name | Type |
---|
commandInstance | InstanceType<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:
Name | Type | Description |
---|
commandInstance | Command | instance 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:
Name | Type |
---|
T | { constructor: (...args: any) => any ; args: Array<{ name: string }> } |
Parameters:
Name | Type | Description |
---|
commandInstance | InstanceType<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
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
+ new SingleCommandHelp(commandInstance
: Command, options?
: Partial<HelpOptions>): SingleCommandHelp
Overrides void
Parameters:
Name | Type |
---|
commandInstance | Command |
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
• Protected
get sortedCommands(): Plugin[]
Inherited from SingleCommandHelp.sortedCommands
Returns: Plugin[]
sortedTopics
• Protected
get sortedTopics(): Topic[]
Inherited from SingleCommandHelp.sortedTopics
Returns: Topic[]
Methods
command
▸ Protected
command(command
: Command): string
Inherited from SingleCommandHelp.command
deprecated
used for readme generation
Parameters:
Name | Type | Description |
---|
command | Command | The command to generate readme help for |
Returns: string
the readme help string for the given command
formatCommand
▸ Protected
formatCommand(command
: Command): string
Inherited from SingleCommandHelp.formatCommand
Parameters:
Returns: string
formatCommands
▸ Protected
formatCommands(commands
: Command[]): string
Inherited from SingleCommandHelp.formatCommands
Parameters:
Name | Type |
---|
commands | Command[] |
Returns: string
formatRoot
▸ Protected
formatRoot(): string
Inherited from SingleCommandHelp.formatRoot
Returns: string
formatTopic
▸ Protected
formatTopic(topic
: Topic): string
Inherited from SingleCommandHelp.formatTopic
Parameters:
Returns: string
formatTopics
▸ Protected
formatTopics(topics
: Topic[]): string
Inherited from SingleCommandHelp.formatTopics
Parameters:
Returns: string
generateHelpText
▸ generateHelpText(): string
Returns: string
showCommandHelp
▸ showCommandHelp(command
: Command): void
Inherited from SingleCommandHelp.showCommandHelp
Overrides void
Parameters:
Returns: void
showHelp
▸ showHelp(argv
: string[]): void
Inherited from SingleCommandHelp.showHelp
Overrides void
Parameters:
Returns: void
showRootHelp
▸ Protected
showRootHelp(): void
Inherited from SingleCommandHelp.showRootHelp
Returns: void
showTopicHelp
▸ Protected
showTopicHelp(topic
: Topic): void
Inherited from SingleCommandHelp.showTopicHelp
Parameters:
Returns: void
Interfaces
@handy-common-utils/oclif-utils
Globals / OclifHelpContent
Interface: OclifHelpContent
Hierarchy
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