Skip to content

Commit

Permalink
feat(cli): enable custom hints in help message
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Jul 5, 2018
1 parent e2a7b6f commit 37c3159
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export const GLOBAL_OPTIONS = {
loglevel: new ChoicesParameter({
alias: "l",
choices: logLevelChoices,
help: "Set logger level, values can be either string or numeric",
help:
"Set logger level. Values can be either string or numeric and are prioritized from 0 to 5 " +
"(highest to lowest) as follows: error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5",
hints:
"[enum] [default: info] [error || 0, warn || 1, info || 2, verbose || 3, debug || 4, silly || 5]",
defaultValue: LogLevel[LogLevel.info],
}),
output: new ChoicesParameter({
Expand Down
6 changes: 4 additions & 2 deletions src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const styleConfig = {
usagePrefix: str => (
`
${chalk.bold(str.slice(0, 5).toUpperCase())}
${chalk.italic(str.slice(7))}`
),
usageCommandPlaceholder: str => chalk.blue(str),
Expand All @@ -34,7 +33,7 @@ ${chalk.bold(str.slice(0, 5).toUpperCase())}
usageOptionsPlaceholder: str => chalk.yellow(str),
group: (str: string) => {
const cleaned = str.endsWith(":") ? str.slice(0, -1) : str
return chalk.bold(cleaned.toUpperCase()) + "\n"
return chalk.bold(cleaned.toUpperCase())
},
flags: (str, _type) => {
const style = str.startsWith("-") ? chalk.green : chalk.magenta
Expand Down Expand Up @@ -115,13 +114,15 @@ export interface SywacOptionConfig {
defaultValue?: any
choices?: any[]
required?: boolean
hints?: string
strict: true
}

export function prepareOptionConfig(param: Parameter<any>): SywacOptionConfig {
const {
defaultValue,
help: desc,
hints,
required,
type,
} = param
Expand All @@ -136,6 +137,7 @@ export function prepareOptionConfig(param: Parameter<any>): SywacOptionConfig {
desc,
required,
type,
hints,
strict: true,
}
if (type === "choice") {
Expand Down
5 changes: 4 additions & 1 deletion src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ParameterConstructor<T> {
alias?: string,
defaultValue?: T,
valueName?: string,
hints?: string,
overrides?: string[],
}

Expand All @@ -35,13 +36,15 @@ export abstract class Parameter<T> {
help: string
required: boolean
alias?: string
hints?: string
valueName: string
overrides: string[]

constructor({ help, required, alias, defaultValue, valueName, overrides }: ParameterConstructor<T>) {
constructor({ help, required, alias, defaultValue, valueName, overrides, hints }: ParameterConstructor<T>) {
this.help = help
this.required = required || false
this.alias = alias
this.hints = hints
this.defaultValue = defaultValue
this.valueName = valueName || "_valueType"
this.overrides = overrides || []
Expand Down

0 comments on commit 37c3159

Please sign in to comment.