Skip to content

Commit ab5c154

Browse files
committed
create-gaarf-wf@1.6.2: added additional checks for correctness of the answer cli argument to improve usability
Change-Id: I18060485f4042a5515242d30bced8ba7a2f99f89
1 parent abda232 commit ab5c154

File tree

6 files changed

+61
-16
lines changed

6 files changed

+61
-16
lines changed

gcp/create-gaarf-wf/README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ An interactive generator for [Gaarf Workflow](https://github.com/google/ads-api-
55
It can be called via `npm init`:
66

77
```
8-
npm init gaarf-wf
8+
npm init gaarf-wf@latest
99
```
1010

1111
Several additional options are supported:
12-
* debug - more detailed output, creates a log file `.create-gaarf-wf-out.log` with std output (stdout/stderr)
13-
* diag - even more details output, forces streaming from all executing commands to console
14-
* answers - use a supplied JSON file as answers for all questions, if the file contains all answers the generation will be non-interactive (usage: `--answers=file.json`)
15-
* save - save all answers into a file (usage: `--save` or `--save=file.json`)
12+
* `debug` - more detailed output, creates a log file `.create-gaarf-wf-out.log` with std output (stdout/stderr)
13+
* `diag` - even more detailed output, forces streaming from all executing commands to console
14+
* `answers` - use a supplied JSON file as answers for all questions, if the file contains all answers the generation will be non-interactive (usage: `--answers=file.json`)
15+
* `save` - save all answers into a file (usage: `--save` or `--save=file.json`)
1616

1717
To pass the options use `--` before them while calling via npm init:
1818
```
19-
npm init gaarf-wf -- --debug
19+
npm init gaarf-wf@latest -- --debug
2020
```
2121

22-
It's supposed that you will be running `npm init gaarf-wf` command in a folder where you placed google-ads.yaml and Ads and BigQuery queries.
22+
It's assumed that you will be running `npm init gaarf-wf` command in a folder where you placed google-ads.yaml and Ads and BigQuery queries.
2323

2424

25-
> Please note that if you're running the tool in Google Cloud Shell then you need to remove npm cache manually via `rm -rf ~/.npm/`.
25+
> Please note that if you're running the tool in Google Cloud Shell then you might need to remove npm cache manually via `rm -rf ~/.npm/`.
26+
27+
It's always better to run `npm init gaarf-wf@latest` not just `npm init gaarf-wf` to make sure you're using the latest version.
28+
If you need some specific version you can specify it as well: `npm init gaarf-wf@1.5.0`. See npm docs on [npm init](https://docs.npmjs.com/cli/v9/commands/npm-init?v=true).
2629

2730
## Disclaimer
2831
This is not an officially supported Google product.

gcp/create-gaarf-wf/build/index.js

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gcp/create-gaarf-wf/build/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gcp/create-gaarf-wf/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gcp/create-gaarf-wf/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-gaarf-wf",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "Interactive generator for Gaarf (Google Ads API Report Fetcher) Workflow",
55
"type": "module",
66
"bin": {

gcp/create-gaarf-wf/src/index.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,36 @@ refresh_token: ${refresh_token}
639639
return path_to_googleads_config;
640640
}
641641

642-
async function init() {
642+
function get_answers(): Partial<any> {
643643
let answers: Partial<any> = {};
644644
if (argv.answers) {
645-
answers = JSON.parse(fs.readFileSync(argv.answers, 'utf-8')) || {};
645+
// users can mistakenly supply `--answers.json` (instead of `answers=answers.json`), in that case argv.answers
646+
if (typeof argv.answers !== 'string') {
647+
console.log(
648+
chalk.red(
649+
'Argument answers does not seem to have a correct value (a file name): ' +
650+
JSON.stringify(argv.answers)
651+
)
652+
);
653+
process.exit(-1);
654+
}
655+
let answersContent;
656+
try {
657+
answersContent = fs.readFileSync(argv.answers, 'utf-8');
658+
} catch (e) {
659+
console.log(
660+
chalk.red(`Answers file ${argv.answers} could not be found or read.`)
661+
);
662+
process.exit(-1);
663+
}
664+
answers = JSON.parse(answersContent) || {};
646665
console.log(`Using answers from '${argv.answers}' file`);
647666
}
667+
return answers;
668+
}
669+
670+
async function init() {
671+
const answers = get_answers();
648672
const status_log = `Running create-gaarf-wf in ${cwd}`;
649673
if (is_debug) {
650674
fs.writeFileSync(LOG_FILE, `[${new Date()}]${status_log}`);

0 commit comments

Comments
 (0)