Skip to content

Commit d229070

Browse files
authored
Merge pull request #68 from eviltester/60-sort-out-clis
cli refactoring and merge into app codebase
2 parents ec39cc2 + 52f9e56 commit d229070

42 files changed

Lines changed: 1242 additions & 709 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/cli-deploy.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ jobs:
4343
zip_name: macos-arm64.zip
4444
smoke_command: ./out/macos-arm64/anywaydata --help
4545
bun_build_flags: --compile
46-
defaults:
47-
run:
48-
working-directory: ./cli
4946
steps:
5047
- uses: actions/checkout@v4
5148
- uses: oven-sh/setup-bun@v2
@@ -56,7 +53,7 @@ jobs:
5653
- name: build binary
5754
shell: bash
5855
run: |
59-
bun build ./index.ts ${{ matrix.bun_build_flags }} --target=${{ matrix.bun_target }} --outfile "${{ github.workspace }}/${{ matrix.bin_relpath }}"
56+
bun build ./apps/cli/src/bun-entry.js ${{ matrix.bun_build_flags }} --target=${{ matrix.bun_target }} --outfile "${{ github.workspace }}/${{ matrix.bin_relpath }}"
6057
- name: smoke test binary
6158
run: ${{ matrix.smoke_command }}
6259
- name: package zip (windows)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Codex PR Review
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
issues: write
10+
11+
concurrency:
12+
group: codex-pr-review-${{ github.workflow }}-${{ github.ref_name }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
codex-review:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Verify OpenAI key is configured
23+
shell: bash
24+
run: |
25+
if [ -z "${{ secrets.OPENAI_API_KEY }}" ]; then
26+
echo "OPENAI_API_KEY is not configured for this run."
27+
exit 1
28+
fi
29+
30+
- name: Run Codex PR review
31+
uses: openai/codex-action@v1
32+
with:
33+
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
34+
prompt: |
35+
Review this pull request for:
36+
- bugs and behavioral regressions
37+
- security or reliability risks
38+
- missing or weak tests
39+
Keep feedback concise and actionable with file/line references.

.github/workflows/node.js.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,31 @@ jobs:
7474
- name: Install dependencies
7575
run: npm ci
7676

77+
- name: CLI pack smoke test
78+
shell: bash
79+
run: |
80+
set -euo pipefail
81+
rm -rf .tmp-pack
82+
mkdir -p .tmp-pack
83+
CORE_TARBALL="$(npm pack --workspace packages/core --pack-destination ./.tmp-pack | tail -n 1)"
84+
CLI_TARBALL="$(npm pack --workspace apps/cli --pack-destination ./.tmp-pack | tail -n 1)"
85+
npm exec --yes \
86+
--package "./.tmp-pack/${CORE_TARBALL}" \
87+
--package "./.tmp-pack/${CLI_TARBALL}" \
88+
anywaydata -- --help >/dev/null
89+
echo "CLI npm pack smoke test passed with local core+cli tarballs: ${CORE_TARBALL}, ${CLI_TARBALL}"
90+
7791
- name: Build
7892
run: npm run build --if-present
7993

94+
- name: Set up Bun
95+
uses: oven-sh/setup-bun@v2
96+
with:
97+
bun-version: 1.2.10
98+
99+
- name: Bun CLI entry smoke test
100+
run: bun run apps/cli/src/bun-entry.js --help
101+
80102
- name: Install Playwright browser
81103
run: npx playwright install --with-deps chromium
82104

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ coverage.txt
1010
test_output.txt
1111
playwright-report
1212
test-results
13+
.tmp

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ This repository now uses npm workspaces:
176176

177177
- `packages/core` -> shared generation engine (`@anywaydata/core`)
178178
- `packages/core-ui` -> browser UI modules (`@anywaydata/core-ui`)
179-
- `packages/cli` -> CLI wrapper (`@anywaydata/cli`)
179+
- `apps/cli` -> npm CLI package (`@anywaydata/cli`)
180180
- `apps/api` -> REST API (`@anywaydata/api`)
181181
- `apps/mcp` -> MCP server (`@anywaydata/mcp`)
182182

@@ -201,7 +201,7 @@ Run an individual workspace command:
201201

202202
## npm CLI Usage (`@anywaydata/cli`)
203203

204-
The npm CLI package is the workspace package `@anywaydata/cli` (separate from the Bun CLI in `cli/`).
204+
The npm CLI package is the workspace app `apps/cli` (`@anywaydata/cli`), and Bun executable builds also use `apps/cli` as the source.
205205

206206
Install globally from npm:
207207

apps/cli/README.md

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
# AnyWayData CLI (`apps/cli`)
2+
3+
Unified CLI implementation for Node and Bun, backed by `@anywaydata/core`.
4+
5+
This workspace is the source of truth for:
6+
7+
- npm/npx CLI usage (`anywaydata`)
8+
- Node runtime entrypoint (`src/node-entry.js`)
9+
- Bun runtime entrypoint (`src/bun-entry.js`)
10+
- Bun executable builds
11+
12+
## Quick Start
13+
14+
Install globally:
15+
16+
```bash
17+
npm install -g @anywaydata/cli
18+
```
19+
20+
Run with npx:
21+
22+
```bash
23+
npx @anywaydata/cli --help
24+
```
25+
26+
Run from repo with Node:
27+
28+
```bash
29+
node apps/cli/src/node-entry.js --help
30+
```
31+
32+
Run from repo with Bun:
33+
34+
```bash
35+
bun run apps/cli/src/bun-entry.js --help
36+
```
37+
38+
## Example Usage
39+
40+
Generate 3 rows from a spec file:
41+
42+
```bash
43+
anywaydata generate -i exampleTestDataSpec.txt -n 3
44+
```
45+
46+
Write to an output file:
47+
48+
```bash
49+
anywaydata generate -i exampleTestDataSpec.txt -n 3 -o output.csv
50+
```
51+
52+
Redirect stdout:
53+
54+
```bash
55+
anywaydata generate -i exampleTestDataSpec.txt -n 3 > output.csv
56+
```
57+
58+
Use included examples in this workspace:
59+
60+
```bash
61+
anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 3 -f csv
62+
anywaydata generate -i ./apps/cli/examples/company.txt -n 3 -f csv
63+
anywaydata generate -i ./apps/cli/examples/regex-field.txt -n 3 -f csv
64+
```
65+
66+
## CLI Options
67+
68+
- `-i, --inputfile` input text spec path (required)
69+
- `-n, --numberOfLines` row count (required, overridden to `1` by `--testMode`)
70+
- `-f, --format` output format (e.g. `csv`, `json`, `jsonl`, `xml`, `sql`)
71+
- `-o, --outputfile` optional output file path
72+
- `-t, --testMode` generate one row and print diagnostics/example output
73+
- `--show-progress` force progress logs on/off
74+
- `--stream` enable stream mode when supported
75+
- `--stream-threshold` auto-enable stream mode when rows >= threshold and output file is set (default `5000`)
76+
- `--unsafe-faker-expressions` allow expression-style faker args (unsafe for untrusted input)
77+
78+
## Streaming Behavior
79+
80+
Streaming is currently supported for:
81+
82+
- `csv`
83+
- `jsonl`
84+
85+
Other formats use buffered generation.
86+
87+
Examples:
88+
89+
```bash
90+
anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 100000 -f jsonl -o output.jsonl --stream
91+
anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 100000 -f csv -o output.csv --stream-threshold 1000
92+
```
93+
94+
## Spec File Format
95+
96+
The test data spec format is two lines per field:
97+
98+
1. Column name
99+
2. Rule/spec for that column
100+
101+
Example:
102+
103+
```text
104+
Column Name 1
105+
Data Value Spec for Column Name 1
106+
Column Name 2
107+
Data Value Spec for Column Name 2
108+
```
109+
110+
### Literal Value Example
111+
112+
```text
113+
Company
114+
AnyWayData
115+
```
116+
117+
### Faker Value Example
118+
119+
```text
120+
Company
121+
company.name
122+
```
123+
124+
Faker API docs:
125+
126+
- https://fakerjs.dev/api/
127+
128+
### Regex Value Example
129+
130+
```text
131+
Regex Generated Field
132+
[A-Z]{3,6}[0-9]{0,6}
133+
```
134+
135+
## Safe vs Unsafe Faker Expressions
136+
137+
CLI is safe-by-default. For untrusted specs, keep default behavior.
138+
139+
To allow expression-style faker arguments, opt in explicitly:
140+
141+
```bash
142+
anywaydata generate -i input.txt -n 10 -f csv --unsafe-faker-expressions
143+
```
144+
145+
## Build Bun Executables
146+
147+
Build a Bun executable from the shared entrypoint:
148+
149+
```bash
150+
bun build ./apps/cli/src/bun-entry.js --compile --target=bun-linux-x64 --outfile ./out/linux-x64/anywaydata
151+
```
152+
153+
Cross-platform targets follow the same pattern:
154+
155+
- `bun-windows-x64`
156+
- `bun-linux-x64`
157+
- `bun-linux-arm64`
158+
- `bun-darwin-arm64`
159+
160+
See Bun executable docs:
161+
162+
- https://bun.sh/docs/bundler/executables

0 commit comments

Comments
 (0)