Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): enforce single character option aliases #152

Merged
merged 1 commit into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following option flags can be used with any of the CLI commands:
| `--root` | `-r` | string | Override project root directory (defaults to working directory).
| `--silent` | `-s` | boolean | Suppress log output.
| `--env` | `-e` | string | The environment (and optionally namespace) to work against
| `--loglevel` | `-log` | `error` `warn` `info` `verbose` `debug` `silly` | Set logger level.
| `--loglevel` | `-l` | `error` `warn` `info` `verbose` `debug` `silly` | Set logger level.
| `--output` | `-o` | `json` `yaml` | Output command result in specified format (note: disables progress logging).

### garden build
Expand Down
15 changes: 12 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,15 @@ export class GardenCli {
}

export async function run(): Promise<void> {
const cli = new GardenCli()
return cli.parse().then(result => shutdown(result.code))
let code
try {
const cli = new GardenCli()
const result = await cli.parse()
code = result.code
} catch (err) {
console.log(err)
code = 1
} finally {
shutdown(code)
}
}
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