Skip to content

Commit

Permalink
Support reading data from stdin (#24)
Browse files Browse the repository at this point in the history
Sometimes the data payload is too large as command line args. This PR
adds support for parsing data from stdin.
  • Loading branch information
ben-z authored Dec 31, 2024
1 parent 7738197 commit c728034
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,40 @@ A collection of email templates used by [WATcloud](https://cloud.watonomous.ca/)

## Development

### Emails

```sh
npm ci
npm run dev
```

Open [localhost:3000](http://localhost:3000) with your browser to see email previews.

Run the following to use the CLI:
### CLI

```sh
npm run build
node ./dist/cli/index.js
```

#### Packaging the CLI

```sh
npm run build
npm version --no-git-tag-version 0.0.0-dev
npm pack --pack-destination .
```

A `watonomous-watcloud-emails-0.0.0-dev.tgz` file will be created in the current directory.
Use it as follows:

```sh
npx watonomous-watcloud-emails-0.0.0-dev.tgz --help
# or
npm install -g watonomous-watcloud-emails-0.0.0-dev.tgz
watcloud-emails --help
```

## Releasing

Releases are manually created from the [Releases page](https://github.com/WATonomous/watcloud-emails/releases).
Expand Down
14 changes: 12 additions & 2 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ program
.action(async (template_name, options) => {
let data = {};
if (options.data) {
data = JSON.parse(options.data);
if (options.data === '-') {
// Read from stdin
data = JSON.parse(fs.readFileSync(0, 'utf-8'));
} else {
data = JSON.parse(options.data);
}
}

const template = await getTemplate(template_name, [data]);
Expand All @@ -57,7 +62,12 @@ program
.action(async (template_name, options) => {
let data = [];
if (options.data) {
data = JSON.parse(options.data);
if (options.data === '-') {
// Read from stdin
data = JSON.parse(fs.readFileSync(0, 'utf-8'));
} else {
data = JSON.parse(options.data);
}
}

const template = await getTemplate(template_name, data);
Expand Down

0 comments on commit c728034

Please sign in to comment.