Skip to content

Commit

Permalink
feat(cli): add guidance to use CLI with submodules (#626)
Browse files Browse the repository at this point in the history
* Add a --help or -h command to the CLI

* Add a few more CLI examples to README

* Use `$` instead of `>` to indicate terminal commands
  • Loading branch information
martinnormark authored and gadicc committed Sep 18, 2023
1 parent 686331e commit 7d08bb1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ considered acknowledgement and acceptance of these terms and of its license.
**CLI** (Command line interface)

```bash
$ npx yahoo-finance2 --help
$ npx yahoo-finance2 search AAPL
$ npx yahoo-finance2 quoteSummary AAPL
$ npx yahoo-finance2 quoteSummary AAPL '{"modules":["assetProfile", "secFilings"]}'

# or install it
$ npm install -g yahoo-finance2
Expand Down
17 changes: 17 additions & 0 deletions bin/yahoo-finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ const script = process.argv[1];
const moduleName = process.argv[2];
const argsAsStrings = process.argv.slice(3);

if (moduleName === "--help" || moduleName === "-h") {
console.log();
console.log("Usage: yahoo-finance.js <module> <args>");
console.log();
console.log("Get a quote for AAPL:");
console.log("$ yahoo-finance.js quoteSummary AAPL");
console.log();
console.log("Run the quoteSummary module with two submodules:");
console.log(
'$ yahoo-finance.js quoteSummary AAPL \'{"modules":["assetProfile", "secFilings"]}\''
);
console.log();
console.log("Available modules:");
console.log(moduleNames.join(", "));
process.exit();
}

if (!moduleNames.includes(moduleName)) {
console.log("No such module: " + moduleName);
console.log("Available modules: " + moduleNames.join(", "));
Expand Down

0 comments on commit 7d08bb1

Please sign in to comment.