-
Notifications
You must be signed in to change notification settings - Fork 4
cli refactoring and merge into app codebase #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e97b386
cli refactoring and merge into app codebase
eviltester 38b76dd
update lock file
eviltester ae248f7
review fixes
eviltester f8aa1b6
restructure further
eviltester 4ef63d8
migrate and update docs
eviltester 8f44658
docs and build update
eviltester b2e67eb
manual review only - key needs to be added
eviltester c446cbc
build fix
eviltester 52f9e56
updates
eviltester File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| name: Codex PR Review | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| issues: write | ||
|
|
||
| concurrency: | ||
| group: codex-pr-review-${{ github.workflow }}-${{ github.ref_name }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| codex-review: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Verify OpenAI key is configured | ||
| shell: bash | ||
| run: | | ||
| if [ -z "${{ secrets.OPENAI_API_KEY }}" ]; then | ||
| echo "OPENAI_API_KEY is not configured for this run." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Run Codex PR review | ||
| uses: openai/codex-action@v1 | ||
| with: | ||
| openai-api-key: ${{ secrets.OPENAI_API_KEY }} | ||
| prompt: | | ||
| Review this pull request for: | ||
| - bugs and behavioral regressions | ||
| - security or reliability risks | ||
| - missing or weak tests | ||
| Keep feedback concise and actionable with file/line references. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ coverage.txt | |
| test_output.txt | ||
| playwright-report | ||
| test-results | ||
| .tmp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| # AnyWayData CLI (`apps/cli`) | ||
|
|
||
| Unified CLI implementation for Node and Bun, backed by `@anywaydata/core`. | ||
|
|
||
| This workspace is the source of truth for: | ||
|
|
||
| - npm/npx CLI usage (`anywaydata`) | ||
| - Node runtime entrypoint (`src/node-entry.js`) | ||
| - Bun runtime entrypoint (`src/bun-entry.js`) | ||
| - Bun executable builds | ||
|
|
||
| ## Quick Start | ||
|
|
||
| Install globally: | ||
|
|
||
| ```bash | ||
| npm install -g @anywaydata/cli | ||
| ``` | ||
|
|
||
| Run with npx: | ||
|
|
||
| ```bash | ||
| npx @anywaydata/cli --help | ||
| ``` | ||
|
|
||
| Run from repo with Node: | ||
|
|
||
| ```bash | ||
| node apps/cli/src/node-entry.js --help | ||
| ``` | ||
|
|
||
| Run from repo with Bun: | ||
|
|
||
| ```bash | ||
| bun run apps/cli/src/bun-entry.js --help | ||
| ``` | ||
|
|
||
| ## Example Usage | ||
|
|
||
| Generate 3 rows from a spec file: | ||
|
|
||
| ```bash | ||
| anywaydata generate -i exampleTestDataSpec.txt -n 3 | ||
| ``` | ||
|
|
||
| Write to an output file: | ||
|
|
||
| ```bash | ||
| anywaydata generate -i exampleTestDataSpec.txt -n 3 -o output.csv | ||
| ``` | ||
|
|
||
| Redirect stdout: | ||
|
|
||
| ```bash | ||
| anywaydata generate -i exampleTestDataSpec.txt -n 3 > output.csv | ||
| ``` | ||
|
|
||
| Use included examples in this workspace: | ||
|
|
||
| ```bash | ||
| anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 3 -f csv | ||
| anywaydata generate -i ./apps/cli/examples/company.txt -n 3 -f csv | ||
| anywaydata generate -i ./apps/cli/examples/regex-field.txt -n 3 -f csv | ||
| ``` | ||
|
|
||
| ## CLI Options | ||
|
|
||
| - `-i, --inputfile` input text spec path (required) | ||
| - `-n, --numberOfLines` row count (required, overridden to `1` by `--testMode`) | ||
| - `-f, --format` output format (e.g. `csv`, `json`, `jsonl`, `xml`, `sql`) | ||
| - `-o, --outputfile` optional output file path | ||
| - `-t, --testMode` generate one row and print diagnostics/example output | ||
| - `--show-progress` force progress logs on/off | ||
| - `--stream` enable stream mode when supported | ||
| - `--stream-threshold` auto-enable stream mode when rows >= threshold and output file is set (default `5000`) | ||
| - `--unsafe-faker-expressions` allow expression-style faker args (unsafe for untrusted input) | ||
|
|
||
| ## Streaming Behavior | ||
|
|
||
| Streaming is currently supported for: | ||
|
|
||
| - `csv` | ||
| - `jsonl` | ||
|
|
||
| Other formats use buffered generation. | ||
|
|
||
| Examples: | ||
|
|
||
| ```bash | ||
| anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 100000 -f jsonl -o output.jsonl --stream | ||
| anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 100000 -f csv -o output.csv --stream-threshold 1000 | ||
| ``` | ||
|
|
||
| ## Spec File Format | ||
|
|
||
| The test data spec format is two lines per field: | ||
|
|
||
| 1. Column name | ||
| 2. Rule/spec for that column | ||
|
|
||
| Example: | ||
|
|
||
| ```text | ||
| Column Name 1 | ||
| Data Value Spec for Column Name 1 | ||
| Column Name 2 | ||
| Data Value Spec for Column Name 2 | ||
| ``` | ||
|
|
||
| ### Literal Value Example | ||
|
|
||
| ```text | ||
| Company | ||
| AnyWayData | ||
| ``` | ||
|
|
||
| ### Faker Value Example | ||
|
|
||
| ```text | ||
| Company | ||
| company.name | ||
| ``` | ||
|
|
||
| Faker API docs: | ||
|
|
||
| - https://fakerjs.dev/api/ | ||
|
|
||
| ### Regex Value Example | ||
|
|
||
| ```text | ||
| Regex Generated Field | ||
| [A-Z]{3,6}[0-9]{0,6} | ||
| ``` | ||
|
|
||
| ## Safe vs Unsafe Faker Expressions | ||
|
|
||
| CLI is safe-by-default. For untrusted specs, keep default behavior. | ||
|
|
||
| To allow expression-style faker arguments, opt in explicitly: | ||
|
|
||
| ```bash | ||
| anywaydata generate -i input.txt -n 10 -f csv --unsafe-faker-expressions | ||
| ``` | ||
|
|
||
| ## Build Bun Executables | ||
|
|
||
| Build a Bun executable from the shared entrypoint: | ||
|
|
||
| ```bash | ||
| bun build ./apps/cli/src/bun-entry.js --compile --target=bun-linux-x64 --outfile ./out/linux-x64/anywaydata | ||
| ``` | ||
|
|
||
| Cross-platform targets follow the same pattern: | ||
|
|
||
| - `bun-windows-x64` | ||
| - `bun-linux-x64` | ||
| - `bun-linux-arm64` | ||
| - `bun-darwin-arm64` | ||
|
|
||
| See Bun executable docs: | ||
|
|
||
| - https://bun.sh/docs/bundler/executables |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| module.exports = { | ||
| verbose: true, | ||
| testEnvironment: 'node', | ||
| transform: { | ||
| '^.+\\.js$': 'babel-jest', | ||
| }, | ||
| testMatch: ['<rootDir>/src/tests/**/*.test.js'], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/usr/bin/env bun | ||
| import { createBunPlatform, runCli } from './index.js'; | ||
|
|
||
| const code = await runCli(process.argv, createBunPlatform()); | ||
| if (code !== 0) { | ||
| process.exit(code); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import yargs from 'yargs'; | ||
| import { hideBin } from 'yargs/helpers'; | ||
| import { SUPPORTED_FORMATS } from '@anywaydata/core'; | ||
|
|
||
| export function parseCliOptions(argvInput = process.argv) { | ||
| const parsed = yargs(hideBin(argvInput)) | ||
| .usage('Usage: anywaydata generate -i input.txt -n 10 -f csv [-o output.txt]') | ||
| .command('generate', 'Generate test data from an input spec') | ||
| .option('i', { alias: 'inputfile', type: 'string', demandOption: true, describe: 'Text file with a data spec' }) | ||
| .option('n', { | ||
| alias: 'numberOfLines', | ||
| type: 'number', | ||
| demandOption: true, | ||
| default: 1, | ||
| describe: 'Number of lines to generate', | ||
| }) | ||
| .option('f', { | ||
| alias: 'format', | ||
| type: 'string', | ||
| default: 'csv', | ||
| describe: `Output format e.g. ${SUPPORTED_FORMATS.join(',')}`, | ||
| }) | ||
| .option('o', { alias: 'outputfile', type: 'string', describe: 'Output file' }) | ||
| .option('t', { | ||
| alias: 'testMode', | ||
| type: 'boolean', | ||
| default: false, | ||
| describe: 'Generate one line, report diagnostics and include example output', | ||
| }) | ||
| .option('show-progress', { | ||
| type: 'boolean', | ||
| default: undefined, | ||
| describe: 'Show progress logs even when writing to file', | ||
| }) | ||
| .option('stream', { | ||
| type: 'boolean', | ||
| default: false, | ||
| describe: 'Use streaming generation path when available (exporting CSV or JSONL)', | ||
| }) | ||
| .option('stream-threshold', { | ||
| type: 'number', | ||
| default: 5000, | ||
| describe: 'Auto-enable stream mode when rows >= threshold and output file is provided', | ||
| }) | ||
| .option('unsafe-faker-expressions', { | ||
| type: 'boolean', | ||
| default: false, | ||
| describe: 'Allow expression-style faker arguments (unsafe for untrusted input)', | ||
| }) | ||
| .help('h') | ||
| .alias('h', 'help') | ||
| .parseSync(); | ||
|
|
||
| const rowCount = parsed.testMode ? 1 : parsed.numberOfLines; | ||
| const streamThreshold = Number.isFinite(parsed.streamThreshold) ? Math.max(0, parsed.streamThreshold) : 5000; | ||
| const shouldStream = parsed.stream === true || (!!parsed.outputfile && rowCount >= streamThreshold); | ||
| const showProgress = | ||
| parsed.showProgress !== undefined ? parsed.showProgress === true : parsed.testMode || !parsed.outputfile; | ||
|
|
||
| return { | ||
| inputFile: parsed.inputfile, | ||
| outputFile: parsed.outputfile, | ||
| format: String(parsed.format || 'csv').toLowerCase(), | ||
| rowCount, | ||
| testMode: parsed.testMode === true, | ||
| showProgress, | ||
| shouldStream, | ||
| unsafeFakerExpressions: parsed['unsafe-faker-expressions'] === true, | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.