Skip to content

Commit

Permalink
fix: Handle unexpected cli options. Add aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrseanryan committed Jan 17, 2020
1 parent a189f52 commit e29658e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ To use:

where `--subDirs` means also view images in sub directories.

If `imageDir` is not given, then `chocolate-bars` will try to open the default photos folder, depending on the OS.
This can be abbreviated to:

`chocolate-bars [--i=<path to image directory>] [--s]`

note: If `--imageDir` (or `--i`) is not given, then `chocolate-bars` will try to open the default photos folder, depending on the OS.

For a full list of options, see the built-in help:

`chocolate-bars --help`

##### b) from the source code

Expand Down Expand Up @@ -123,6 +131,10 @@ example:

where `--subDirs` means also view images in sub directories.

For a full list of options, see the built-in help:

`./go.sh --help`

### keyboard shortcuts

A number of keyboard shortcuts are available:
Expand Down
53 changes: 29 additions & 24 deletions src/utils/ArgsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,35 @@ export type Args = {

export namespace ArgsParser {
export function parse(): Args {
const argv = yargs.options({
imageDir: {
type: "string",
default: getDefaultImageDirForOs(),
description:
"The folder containing images. Defaults to typical locations for your OS."
},
shrink: {
type: "boolean",
default: false,
description:
"Shrink images the given imageDir. Internal option that you do not normally need to use."
},
subdirs: {
type: "boolean",
default: false,
description: "If true, then also show images from sub-folders."
},
verbose: {
type: "boolean",
default: false,
description: "If true, then use verbose logging."
}
}).argv;
const argv = yargs
.options({
imageDir: {
alias: "i",
type: "string",
default: getDefaultImageDirForOs(),
description:
"The folder containing images. Defaults to typical locations for your OS."
},
shrink: {
type: "boolean",
default: false,
description:
"Make shrunken copies of images in the given imageDir. This is an internal option that you do not normally need to use."
},
subdirs: {
alias: "s",
type: "boolean",
default: false,
description: "If true, then also show images from sub-folders."
},
verbose: {
alias: "v",
type: "boolean",
default: false,
description: "If true, then use verbose logging."
}
})
.strict().argv;

const imageDir = argv.imageDir || getDefaultImageDirForOs();

Expand Down
9 changes: 9 additions & 0 deletions test-global-cli-bad-args.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

yarn build:minimal

yarn build:cli

node ./dist/lib/cli.js --badArg --verbose

0 comments on commit e29658e

Please sign in to comment.