Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix stdin parsing #33

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1249,14 +1249,12 @@ _See code: [@oclif/plugin-update](https://github.com/oclif/plugin-update/blob/v1

## Templates

The queries parsed by the analytics:fetch command are actually [Handlebar templates](https://handlebarsjs.com/).
This allows some level of scripting, which aids in automation workflows that use the CLI. There are a
number of date related helpers available to use in the template, which provide a means to configure query
windows using relative dates. At some point, this behavior may be available in the API. For now, this
is a feature of the CLI.
There are a number of date related helpers supported in the API available to use in analytic queries
(the `analytics` commands), which provide a means to configure query windows using relative dates.

_Functions Available as Helpers:_

- `maxDateAvailable`
- `yesterday`
- `startOfMonth`
- `startOfLastMonth`
Expand All @@ -1273,8 +1271,7 @@ _Functions Available as Helpers:_
- `startOfNMonthsAgo(n)`
- `endOfNMonthsAgo(n)`

To call one of the functions that takes a parameter, exclude the parenthesis. e.g. `{{nDaysAgo n}}`. More information
on helpers can be found [here](https://handlebarsjs.com/guide/expressions.html#helpers).
To call one of the functions that takes a parameter, exclude the parenthesis. e.g. `{{nDaysAgo n}}`.

_Example Usage:_

Expand Down
88 changes: 3 additions & 85 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"cli-ux": "^6.0.9",
"csv": "6.0.4",
"fast-csv": "^4.3.6",
"handlebars": "^4.7.7",
"inquirer": "^7.3.3",
"listr": "^0.14.3",
"lodash": "^4.17.21",
Expand Down
13 changes: 1 addition & 12 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import {
capitalize as _capitalize,
join as _join,
map as _map,
each as _each,
} from 'lodash';

import * as Handlebars from 'handlebars';
import moment = require('moment');

const DATE_FMT = 'YYYY-MM-DD';
Expand Down Expand Up @@ -80,21 +78,12 @@ export const dateUtils = {
},
};

_each(dateUtils, (val: (params?: any) => string, key: string) => {
Handlebars.registerHelper(key, val);
});

export function verifyDateRange(startDateStr: string, endDateStr: string) {
return moment(startDateStr, DATE_FMT)
.startOf('day')
.isBefore(moment(endDateStr, DATE_FMT).endOf('day'));
}

export function parseTemplate(data: string, ctx?: any): string {
const template = Handlebars.compile(data);
return template(ctx);
}

export async function parseStdin(): Promise<any> {
return new Promise((resolve) => {
const rl = readline.createInterface(process.stdin);
Expand All @@ -103,7 +92,7 @@ export async function parseStdin(): Promise<any> {
data += l;
});
rl.on('close', () => {
resolve(JSON.parse(parseTemplate(data)));
resolve(JSON.parse(data));
});
});
}
Expand Down