Skip to content

Commit

Permalink
Merge branch '10434-story' into 10434-test
Browse files Browse the repository at this point in the history
  • Loading branch information
John Cruz committed Dec 13, 2024
2 parents 51b2211 + 141537c commit 5d7cb59
Show file tree
Hide file tree
Showing 9 changed files with 934 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
orbs:
git-shallow-clone: guitarrapc/[email protected]

efcms-docker-image: &efcms-docker-image $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/ef-cms-us-east-1:4.3.21
efcms-docker-image: &efcms-docker-image $AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/ef-cms-us-east-1:4.3.21.1

parameters:
run_build_and_deploy:
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ RUN apt-get install -y \
jq \
graphicsmagick \
ghostscript \
chromium \
openssh-client \
postgresql-client \
sudo
Expand Down
1 change: 1 addition & 0 deletions scripts/jest-scripts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const config: Config = {
'!reports/**',
'!run-once-scripts/**',
'!set-maintenance-mode-locally.ts',
'!template.ts',
'!upload-practitioner-application-packages.ts',
'!user/**',
'!postgres/**',
Expand Down
73 changes: 73 additions & 0 deletions scripts/reports/reportUtils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
## Argument Parser for Shell Scripts Written in TypeScript

The argument parser is a wrapper of the node:utils `parseArgs` method that aims to standardize how we write shell scripts in TypeScript and centralize text transformation of parsed arguments.

### How to Use the Argument Parser in a Shell Script

Let's say you want the `$1` (first positional) argument to be required and you want to optionally support two additional arguments. Now you can define a `ScriptConfig` object at the top of your script:

```typescript
const scriptConfig: ScriptConfig = {
description: 'some-script.ts - works wonders',
parameters: {
eventCode: {
position: 0,
required: true,
type: 'string',
},
fiscal: {
default: false,
short: 'f',
type: 'boolean',
},
year: {
default: '2024',
short: 'y',
transform: 'number',
type: 'string',
},
},
};
```

And then elsewhere in the script you can get the values from the argument parser thusly:

```typescript
const { eventCode, fiscal, verbose, year } = parseArguments(scriptConfig);
```

### In Action

Given the configuration above, say you call your script like so:

```bash
npx ts-node --transpile-only scripts/some-script.ts NOA -f
```

The argument parser will return the following:

```typescript
{
eventCode: 'NOA',
fiscal: true,
year: 2024,
};
```

### Self-Documenting

All scripts that utilize the argument parser will get a `--help` flag that, when provided, will output usage information automatically generated from the `ScriptConfig` configuration object.

Again, given the configuration above, say you call your script like so:

```bash
npx ts-node --transpile-only scripts/some-script.ts --help
```

The argument parser will print the following:

```
some-script.ts - works wonders
Usage: some-script.ts <eventCode> [ -f -y <year> ]
```
Loading

0 comments on commit 5d7cb59

Please sign in to comment.