Skip to content

Commit

Permalink
Merge pull request #152 from garden-io/single-char-aliases
Browse files Browse the repository at this point in the history
fix(cli): enforce single character option aliases
  • Loading branch information
edvald authored Jun 6, 2018
2 parents e4f85a2 + a49e799 commit c54c16d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
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

0 comments on commit c54c16d

Please sign in to comment.