Skip to content

Commit

Permalink
[email protected]: added additional checks for correctness of the…
Browse files Browse the repository at this point in the history
… answer cli argument to improve usability

Change-Id: I18060485f4042a5515242d30bced8ba7a2f99f89
  • Loading branch information
evil-shrike committed May 17, 2023
1 parent abda232 commit ab5c154
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 16 deletions.
19 changes: 11 additions & 8 deletions gcp/create-gaarf-wf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ An interactive generator for [Gaarf Workflow](https://github.com/google/ads-api-
It can be called via `npm init`:

```
npm init gaarf-wf
npm init gaarf-wf@latest
```

Several additional options are supported:
* debug - more detailed output, creates a log file `.create-gaarf-wf-out.log` with std output (stdout/stderr)
* diag - even more details output, forces streaming from all executing commands to console
* 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`)
* save - save all answers into a file (usage: `--save` or `--save=file.json`)
* `debug` - more detailed output, creates a log file `.create-gaarf-wf-out.log` with std output (stdout/stderr)
* `diag` - even more detailed output, forces streaming from all executing commands to console
* `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`)
* `save` - save all answers into a file (usage: `--save` or `--save=file.json`)

To pass the options use `--` before them while calling via npm init:
```
npm init gaarf-wf -- --debug
npm init gaarf-wf@latest -- --debug
```

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.
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.


> 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/`.
> 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/`.
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.
If you need some specific version you can specify it as well: `npm init [email protected]`. See npm docs on [npm init](https://docs.npmjs.com/cli/v9/commands/npm-init?v=true).

## Disclaimer
This is not an officially supported Google product.
Expand Down
22 changes: 20 additions & 2 deletions gcp/create-gaarf-wf/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gcp/create-gaarf-wf/build/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gcp/create-gaarf-wf/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gcp/create-gaarf-wf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-gaarf-wf",
"version": "1.6.1",
"version": "1.6.2",
"description": "Interactive generator for Gaarf (Google Ads API Report Fetcher) Workflow",
"type": "module",
"bin": {
Expand Down
28 changes: 26 additions & 2 deletions gcp/create-gaarf-wf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,36 @@ refresh_token: ${refresh_token}
return path_to_googleads_config;
}

async function init() {
function get_answers(): Partial<any> {
let answers: Partial<any> = {};
if (argv.answers) {
answers = JSON.parse(fs.readFileSync(argv.answers, 'utf-8')) || {};
// users can mistakenly supply `--answers.json` (instead of `answers=answers.json`), in that case argv.answers
if (typeof argv.answers !== 'string') {
console.log(
chalk.red(
'Argument answers does not seem to have a correct value (a file name): ' +
JSON.stringify(argv.answers)
)
);
process.exit(-1);
}
let answersContent;
try {
answersContent = fs.readFileSync(argv.answers, 'utf-8');
} catch (e) {
console.log(
chalk.red(`Answers file ${argv.answers} could not be found or read.`)
);
process.exit(-1);
}
answers = JSON.parse(answersContent) || {};
console.log(`Using answers from '${argv.answers}' file`);
}
return answers;
}

async function init() {
const answers = get_answers();
const status_log = `Running create-gaarf-wf in ${cwd}`;
if (is_debug) {
fs.writeFileSync(LOG_FILE, `[${new Date()}]${status_log}`);
Expand Down

0 comments on commit ab5c154

Please sign in to comment.