Skip to content

Commit

Permalink
fix(cli): enforce single character option aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Jun 6, 2018
1 parent e4f85a2 commit acb4fa0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const GLOBAL_OPTIONS = {
}),
env: new EnvironmentOption(),
loglevel: new ChoicesParameter({
alias: "log",
alias: "l",
choices: enumToArray(LogLevel),
help: "Set logger level.",
defaultValue: LogLevel[LogLevel.info],
Expand Down Expand Up @@ -300,6 +300,11 @@ export class GardenCli {
}

export async function run(): Promise<void> {
const cli = new GardenCli()
return cli.parse().then(result => shutdown(result.code))
try {
const cli = new GardenCli()
return cli.parse().then(result => shutdown(result.code))
} catch (err) {
console.log(err)
shutdown(1)
}
}
10 changes: 8 additions & 2 deletions src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,14 @@ export function falsifyConflictingParams(argv, params: ParameterValues<any>): Fa
}

// Sywac specific transformers and helpers
export function getOptionSynopsis(key: string, param: Parameter<any>): string {
return param.alias ? `-${param.alias}, --${key}` : `--${key}`
export function getOptionSynopsis(key: string, { alias }: Parameter<any>): string {
if (alias && alias.length > 1) {
throw new InternalError("Option aliases can only be a single character", {
optionName: key,
alias,
})
}
return alias ? `-${alias}, --${key}` : `--${key}`
}

export function getArgSynopsis(key: string, param: Parameter<any>) {
Expand Down

0 comments on commit acb4fa0

Please sign in to comment.