diff --git a/.talismanrc b/.talismanrc index b75914ab..89a683c4 100644 --- a/.talismanrc +++ b/.talismanrc @@ -153,11 +153,11 @@ fileignoreconfig: ignore_detectors: - filename - filename: src/environments/environment.presenter.ts - checksum: 505f5e76e34ab9081cb0d57d6c017799bf0c7d86a08bb77201c6737a1affbaef + checksum: a0bede780ca4e4e95ebef6f4aac9aa9badb88e12beb794062e6be55fe3c6cb24 ignore_detectors: - filename - filename: src/environments/environment.presenter.test.ts - checksum: 9120a7bc0ce7e7307be8bc76e5e7133f13c0ed186bcb932de9e9fba364a30c99 + checksum: 6d05bb10a3aca5d55b9526f395efa7f7b5b0c647533c36558bbdc6481c23fae3 ignore_detectors: - filename - filename: src/environments/environment.resolver.ts @@ -236,7 +236,7 @@ fileignoreconfig: - "a project name passed on argv to the project resolver" - "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)" - filename: AGENTS.md - checksum: a22a2af80687d90bacdcb57392c85afce3f97eb09ac8347c32e6da80809bcb75 + checksum: 46584ecc6343552c40b96b2b5c76a60c1b87ef454fa82f9c901086bcd408b090 allowed_patterns: - "Do not add an exemption to a guard to make a new file pass" - "passes its own error wording to `client.request\\(req, MESSAGES\\)`" @@ -247,9 +247,9 @@ fileignoreconfig: - "a test passes `var`, `env-file` and `from-stack`" - "an in-flight secret registry to redact against" - filename: src/core/project-config.ts - checksum: 1f19da706128ee78e1fe20d8624626038893d908a7061b3f2633e741a77c93b6 + checksum: 9f0c3b2633d311d9f51ea57d3ec6a081b0102c9ebdb3cf37f08f46d00267e069 - filename: src/core/project-config.test.ts - checksum: 65c0a613ec77d4dc6727224d4d097de4a02b300339286db692dbaea9379565ae + checksum: 55746e82d59077579975cf306633a03e6c2471b89fe29ab549c2050113a82c60 - filename: src/core/resolve.ts checksum: a5608d22286efdd4915639faff6e05a588e60e205c74e0398e389822eb8c7292 - filename: src/core/resolve.test.ts @@ -265,13 +265,13 @@ fileignoreconfig: - filename: test/integration/projects-delete.test.ts checksum: 19784ba572daac76e6ef0b004c19cdb9c3f9cb22f738b3ab0e22c694e049026c - filename: src/core/launch-command.ts - checksum: 91ec87522df77d8ed593c95e1a2259d1555acbd1dee95ad8ca4d6c3fa9c61468 + checksum: 2d08f5559ad8700462e7dd0b2768305a47f5b0b87f43b961bdbf1767a0e2540b - filename: src/core/launch-command.test.ts - checksum: 44f0639fe66598ba2f3ba0ddc7edd68381f7aa36e3be5323ecbe5d101a1953a2 + checksum: d0ba482a3e05a3e73ed4d3f8087af6de52e692d0105d064982ba11dd8072df1b - filename: src/projects/project.inputs.test.ts checksum: 8242f4d40388f1a7f1d08c11d2571cb45a9294069a8248a5272bc5606807bb60 - filename: test/integration/projects-command-flows.test.ts - checksum: 1731d2350269ae9b6f7c2837db8e14575f94a9a3fa11f8f86c532717378d99ce + checksum: ede00ae963c4d64ec41dce31cb59d7d58c22ebff18ae670be55192e43fa94290 - filename: src/core/redact.test.ts checksum: ae497ea8c3a4c3f12217d2c4c028a1da3d1324e18362d68c355ba8120902bcb3 - filename: src/commands/launch/projects/list.test.ts @@ -281,7 +281,7 @@ fileignoreconfig: - filename: src/commands/launch/projects/get.test.ts checksum: 3aeffc4e4742ea9c5b3d9e6c5ea2248ced1d19a273bbc7d7948d471774b0d739 - filename: test/integration/projects-list-command.test.ts - checksum: 5f49dc7f384fb9e33c8fb91f1c67b17ffc2fd3bbde3663f90f820056407e98a0 + checksum: 6e294022573c525a0788f99bbea5cd6cfda3140079190e6fb078bd2c52ea1c6b - filename: src/functions/cloud-functions.test.ts checksum: a9d4515bdc953808a1dda094b62dd19af4eed432a553d9f14773b85f1c5346cc - filename: src/functions/function.errors.ts @@ -309,7 +309,7 @@ fileignoreconfig: - filename: src/core/search-list.test.ts checksum: 4e5db3cd6a213db71c51bf5ac8d6a5547ea9ca137d425c00026453e5c3b543b7 - filename: src/core/catalog.test.ts - checksum: 950d5cbb8ebdbe13cf13908b72d5409f7fdf7515c9d93a7c84045efcf4420543 + checksum: 5f79096b43a3b3c6b03f6c86e8f2fbd5c77424e9889a74fd9de12852814620bd - filename: test/credential-guard.setup.ts checksum: 519ccbeb0552fdb1d5f27308c56477c0258ee6cc0adec8f618e8e5bc047cbf6d - filename: src/environments/types.ts @@ -355,7 +355,7 @@ fileignoreconfig: - filename: src/stacks/stacks.api.ts checksum: d59622ca6411b93d5469a1895b08ccde4b9cd83fbb909c82076ea70d74b5e1e4 - filename: src/variables/variable.chooser.ts - checksum: 767bbcee93b0c10c5c9d0b526ce57770cc6323be52d8a4cc1c0452c880b5ab8e + checksum: 7b286b31c49e7501fed220cc6d8c082a451bf8c81b0202242545cff7031e22bb - filename: src/variables/variable.create.test.ts checksum: a2650ca8e081afcf76c801d20e2df4baa96f814d1513080ba24971db0ae3a1bf - filename: src/variables/variable.dotenv.test.ts @@ -475,7 +475,7 @@ fileignoreconfig: - filename: src/secrets/secrets.api.ts checksum: be8e726215a79dbf99f26449d268dacd1b8baad823f74b7c4b0748f6d828402c - filename: src/commands/launch/secrets/list.ts - checksum: 4de3fb4afae29e7e98b3629f61d769597810e7682e336edd28c589515d81e47a + checksum: fea24dc39cd63d2f3b0721c386958388e80df4f885de906c3d3b976c9f77fe10 - filename: src/secrets/secrets.errors.ts checksum: 4a3a6cc9af567658149bdcba8dc5dd0de2a6cb2294bd6f1018b253e709ff1436 - filename: src/secrets/secrets.api.test.ts diff --git a/AGENTS.md b/AGENTS.md index 447ebe74..461c404a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,6 +60,8 @@ file and line that broke its rule, and each was proven red by reintroducing its | `test/guards/tty-streams.test.ts` | `stdin.isTTY`, and the `isTTY` it becomes on the service context, are read only to decide whether the CLI may prompt (a read next to a prompt or a refusal to prompt) or on the plumbing lines that carry it there. Anything deciding what to draw reads `outputIsTTY` / `process.stdout.isTTY`. | D6: heartbeat drawn into a redirected file | | `test/integration/deployments-request-bodies.test.ts` | A deployments mutation puts on the wire only the fields the management service DTO declares - `{commitHash?, uploadUid?}` for a create, `{deployment, reason?}` for a rollback - and never `environment`, which is the URL path. The service validates with `whitelist` and `forbidNonWhitelisted`, so any other key is a bare 400. | Live harness: `deployments:create` and `:rollback` sent `{environment, ...}` and failed with `Bad request` | | `test/integration/retired-commands.test.ts` (named commands) | Every `launch:…` command named anywhere in `src` - a retirement message, a failure hint, an example - is either a registered command or on `PLANNED_COMMANDS` with the ticket that builds it, and a command drops off that list once it ships. | Review: retirement messages and hints pointed at commands the beta does not have | +| `test/guards/whole-number-flags.test.ts` | No source declares `Flags.integer`. A number flag is built with `wholeNumberFlag` in `src/core/catalog.ts`, whose parse throws a `FlagValueError` naming the flag and its range, so a bad value prints one sentence and exits 2 instead of oclif's `Parsing --limit` / `Expected an integer…` text. | Section 10.6: `--limit abc`, `--limit 0` and `--skip -1` printed raw oclif text | +| `test/guards/narrow-terminal.test.ts` | The real list and detail tables (`env:list`, `env:get`, `deployments:list`, `deployments:get`, `projects:list`, `projects:get`), drawn at 30 to 100 columns, print no line wider than the terminal, no ellipsis, and every UID whole on one line; a detail table also prints every field label whole and never as a `FIELD`/`VALUE` record. `renderTable` shrinks the widest column first, never below `minWidth` (`UID_WIDTH` for UID and detail-value columns) or ten characters, never shrinks a `label` column, and wraps cell text instead of cutting it. When the columns cannot fit, a detail table prints ` ` lines and any other table prints each record as a stacked `LABEL value` list; a value that would not fit beside its label goes on its own line indented two spaces. A UID is never wrapped, so 26 columns (two spaces and a UID) is the narrowest terminal the guarantee holds for. | Section 10.9: only the first column shrank, so `env:list` stayed 135 wide and `deployments:list` cut the deployment UID; PR #302 review: detail labels broke mid-word near 45 columns | | `test/guards/prompt-funnel.test.ts` | Every prompt goes through `LaunchCommand`'s `ux`, built once as `cancelOnInterrupt(terminalUx)`, so Ctrl-C at any prompt exits 3. `terminalUx` (`src/core/terminal-ux.ts`) asks cli-utilities' own inquirer instance (`promptLibrary()`) directly, because `cliux.inquire` catches inquirer 12's `ExitPromptError` and calls `process.exit(130)` itself. In raw mode Ctrl-C reaches inquirer as typed input, not as a process `SIGINT`: an `@inquirer/core` prompt (input, list, checkbox, confirm) rejects with `ExitPromptError`, which the wrapper turns into `CancelledError`; the legacy `search-list` rejects with `AbortPromptError` and then raises a real `SIGINT`, so the wrapper cancels on the rejection at once and stays attached only to absorb that signal. The wrapper stays attached to `SIGINT` until the signal has reached every listener (it detaches in a microtask): inquirer's `cli-cursor` loads `signal-exit`, which re-raises `SIGINT` - exit 130 - when it finds itself the only listener, so a `once` listener made every list and checkbox prompt exit 130 (`src/core/interruptible-ux.test.ts` pins it). No source calls `cliux.inquire` / `prompt` / `confirm` under any name, hands `cliux` on as a value, imports a prompt library, uses `promptLibrary` outside `search-list.ts` and `terminal-ux.ts`, or uses `terminalUx` anywhere but that one funnel line; `search-list.ts` may register a type but never prompt. `test/integration/prompt-ctrl-c-on-a-terminal.test.ts` types a real Ctrl-C at each kind of prompt on a pseudo-terminal, because a simulated `SIGINT` is what let CL-8790 through. `test/support/pty/press-ctrl-c.py ` (Python's stdlib `pty`, so `npm test` needs `python3`) runs the command on a pty, types Ctrl-C once `` is on screen and prints the exit code: negative for a signal death (-2 is SIGINT), 124 if `` never appeared, 125 if the command was still running 30 s later (it is killed). `ctrl-c-prompt.fixture.ts` calls `process.exit` with the error's exit code, as oclif's `Errors.handle` does for the CLI. | D2: Ctrl-C exited 130; CL-8790: it did again after cli-utilities 2 | A new prompt, request, render path or command is covered by these guards without being listed in @@ -638,7 +640,8 @@ it (`projectConfigLoader`), so a V1 file whose branch blocks disagree does not b flags already supply everything; a file named with `--config` is still read at once. **The config-file notice.** When any input came from the file, `LaunchCommand.init` prints one line -through `this.ux.print` (stdout, like every other line the CLI prints), worded by +to **stderr** (`writeToStderr`), so a captured stdout such as `url=$(csdx launch:site:open …)` holds +only the command's own output, worded by `configSourceNotice` in `src/core/project-config.ts` from the `configLabel` of each such input and the **full path** of the file actually read (a relative `--config` is resolved first): `Using the organization and project UIDs from /Users/me/site/.cs-launch.json.` (one input: `Using the project UID diff --git a/src/commands/launch/deployments/get.ts b/src/commands/launch/deployments/get.ts index cbcdf63c..f5e1ecb9 100644 --- a/src/commands/launch/deployments/get.ts +++ b/src/commands/launch/deployments/get.ts @@ -2,11 +2,7 @@ import { UsageError } from '../../../core/errors'; import { LaunchCommand } from '../../../core/launch-command'; import { flagsFor, inputs } from '../../../core/inputs'; import { renderTable } from '../../../core/render'; -import { - DEPLOYMENT_DETAIL_COLUMNS, - DEPLOYMENT_VALUE_COLUMN, - deploymentDetailRows, -} from '../../../deployments/deployment.presenter'; +import { DEPLOYMENT_DETAIL_COLUMNS, deploymentDetailRows } from '../../../deployments/deployment.presenter'; import { fetchDeployment } from '../../../deployments/deployment.resolver'; const getInputs = inputs({ @@ -48,7 +44,6 @@ export default class DeploymentsGet extends LaunchCommand { DEPLOYMENT_DETAIL_COLUMNS, deploymentDetailRows(deployment, project.projectType !== 'FILEUPLOAD', scope), process.stdout.columns, - DEPLOYMENT_VALUE_COLUMN, this.services.outputIsTTY, ); } diff --git a/src/commands/launch/deployments/list.ts b/src/commands/launch/deployments/list.ts index 59b98da5..78720720 100644 --- a/src/commands/launch/deployments/list.ts +++ b/src/commands/launch/deployments/list.ts @@ -39,7 +39,6 @@ export default class DeploymentsList extends LaunchCommand { deploymentColumns(project.projectType !== 'FILEUPLOAD'), deployments, process.stdout.columns, - undefined, this.services.outputIsTTY, ); renderPagination(this.ux, { ...page.pagination, skip: this.resolved.skip }, deployments.length); diff --git a/src/commands/launch/env/get.ts b/src/commands/launch/env/get.ts index 16b500fd..bbc302d0 100644 --- a/src/commands/launch/env/get.ts +++ b/src/commands/launch/env/get.ts @@ -1,11 +1,7 @@ import { LaunchCommand } from '../../../core/launch-command'; import { flagsFor, inputs } from '../../../core/inputs'; import { renderTable } from '../../../core/render'; -import { - ENVIRONMENT_DETAIL_COLUMNS, - ENVIRONMENT_VALUE_COLUMN, - environmentDetailRows, -} from '../../../environments/environment.presenter'; +import { ENVIRONMENT_DETAIL_COLUMNS, environmentDetailRows } from '../../../environments/environment.presenter'; const getInputs = inputs({ org: { required: true }, project: { required: true }, env: { required: true } }); @@ -30,7 +26,6 @@ export default class EnvironmentsGet extends LaunchCommand { ENVIRONMENT_DETAIL_COLUMNS, environmentDetailRows({ ...environment, project: this.resolved.project }, project.projectType !== 'FILEUPLOAD'), process.stdout.columns, - ENVIRONMENT_VALUE_COLUMN, this.services.outputIsTTY, ); } diff --git a/src/commands/launch/env/list.ts b/src/commands/launch/env/list.ts index ca29ac79..acfc7844 100644 --- a/src/commands/launch/env/list.ts +++ b/src/commands/launch/env/list.ts @@ -26,7 +26,6 @@ export default class EnvironmentsList extends LaunchCommand { environmentColumns(project.projectType !== 'FILEUPLOAD'), page.environments, process.stdout.columns, - undefined, this.services.outputIsTTY, ); renderPagination(this.ux, { ...page.pagination, skip: this.resolved.skip }, page.environments.length); diff --git a/src/commands/launch/projects/get.ts b/src/commands/launch/projects/get.ts index 42dddd6b..36730de4 100644 --- a/src/commands/launch/projects/get.ts +++ b/src/commands/launch/projects/get.ts @@ -1,7 +1,7 @@ import { LaunchCommand } from '../../../core/launch-command'; import { flagsFor, inputs } from '../../../core/inputs'; import { renderTable } from '../../../core/render'; -import { PROJECT_DESCRIPTION_COLUMN, PROJECT_DETAIL_COLUMNS } from '../../../projects/project.presenter'; +import { PROJECT_DETAIL_COLUMNS } from '../../../projects/project.presenter'; const getInputs = inputs({ org: { required: true }, project: { required: true } }); @@ -20,13 +20,6 @@ export default class ProjectsGet extends LaunchCommand { project: this.resolved.project, }); - renderTable( - this.ux, - PROJECT_DETAIL_COLUMNS, - [result], - process.stdout.columns, - PROJECT_DESCRIPTION_COLUMN, - this.services.outputIsTTY, - ); + renderTable(this.ux, PROJECT_DETAIL_COLUMNS, [result], process.stdout.columns, this.services.outputIsTTY); } } diff --git a/src/commands/launch/projects/list.ts b/src/commands/launch/projects/list.ts index 20271dbf..e888ec79 100644 --- a/src/commands/launch/projects/list.ts +++ b/src/commands/launch/projects/list.ts @@ -21,14 +21,7 @@ export default class ProjectsList extends LaunchCommand { skip: this.resolved.skip, }); - renderTable( - this.ux, - PROJECT_COLUMNS, - page.projects, - process.stdout.columns, - undefined, - this.services.outputIsTTY, - ); + renderTable(this.ux, PROJECT_COLUMNS, page.projects, process.stdout.columns, this.services.outputIsTTY); renderPagination(this.ux, { ...page.pagination, skip: this.resolved.skip }, page.projects.length); } } diff --git a/src/commands/launch/secrets/list.ts b/src/commands/launch/secrets/list.ts index 23ab0adb..2076bfd8 100644 --- a/src/commands/launch/secrets/list.ts +++ b/src/commands/launch/secrets/list.ts @@ -33,13 +33,6 @@ export default class SecretsList extends LaunchCommand { return; } - renderTable( - this.ux, - secretColumns(), - secrets, - process.stdout.columns, - undefined, - this.services.outputIsTTY === true, - ); + renderTable(this.ux, secretColumns(), secrets, process.stdout.columns, this.services.outputIsTTY === true); } } diff --git a/src/commands/launch/variables/list.ts b/src/commands/launch/variables/list.ts index 57c9061f..dd44088f 100644 --- a/src/commands/launch/variables/list.ts +++ b/src/commands/launch/variables/list.ts @@ -36,7 +36,6 @@ export default class VariablesList extends LaunchCommand { variableColumns(environment.updatedAt), page.variables, process.stdout.columns, - undefined, this.services.outputIsTTY, ); renderPagination(this.ux, page.pagination, page.variables.length); diff --git a/src/core/catalog.test.ts b/src/core/catalog.test.ts index ee9a7184..ab8c2563 100644 --- a/src/core/catalog.test.ts +++ b/src/core/catalog.test.ts @@ -2,6 +2,7 @@ import { Parser } from '@oclif/core'; import { coreFlags } from './catalog'; import { CLIENT_MAX_LIMIT } from './constants'; +import { FlagValueError } from './errors'; async function parse(argv: string[]): Promise> { const { flags } = await Parser.parse(argv, { flags: coreFlags }); @@ -33,30 +34,54 @@ describe('coreFlags', () => { await expect(parse(['-c', './.cs-launch.json'])).rejects.toThrow(/Nonexistent flag: -c/); }); - it('advertises the limit range in the flag itself, not only in the help text', () => { - expect(coreFlags.limit).toMatchObject({ min: 1, max: CLIENT_MAX_LIMIT }); + it('advertises the limit range in the help text', () => { expect(coreFlags.limit.description).toBe(`Number of records to fetch (1-${CLIENT_MAX_LIMIT})`); }); - it('advertises the skip floor in the flag itself', () => { - expect(coreFlags.skip).toMatchObject({ min: 0 }); - expect((coreFlags.skip as unknown as { max?: number }).max).toBeUndefined(); - }); - - it.each([['1'], ['2'], [String(CLIENT_MAX_LIMIT)]])('accepts the in-range limit %s', async (limit) => { + it.each([['1'], ['2'], [String(CLIENT_MAX_LIMIT)], [' 7 ']])('accepts the in-range limit %p', async (limit) => { await expect(parse(['--limit', limit])).resolves.toMatchObject({ limit: Number(limit) }); }); - it.each([['0'], ['-1'], [String(CLIENT_MAX_LIMIT + 1)], ['99999']])('rejects the out-of-range limit %s', async (limit) => { - await expect(parse(['--limit', limit])).rejects.toThrow(/Expected an integer/); - }); + it.each([['0'], ['-1'], [String(CLIENT_MAX_LIMIT + 1)], ['99999'], ['abc'], ['1.5'], ['1e2'], ['0x10'], [''], [' ']])( + 'rejects the limit %p with one sentence naming the flag and its range', + async (limit) => { + const failure = await parse(['--limit', limit]).catch((error: unknown) => error); + + expect(failure).toBeInstanceOf(FlagValueError); + expect((failure as FlagValueError).detail).toBe( + `Invalid --limit value "${limit}". Provide a whole number from 1 to ${CLIENT_MAX_LIMIT}.`, + ); + }, + ); it.each([['0'], ['5'], ['1000000']])('accepts the non-negative skip %s', async (skip) => { await expect(parse(['--skip', skip])).resolves.toMatchObject({ skip: Number(skip) }); }); - it.each([['-1'], ['-5']])('rejects the negative skip %s', async (skip) => { - await expect(parse(['--skip', skip])).rejects.toThrow(/Expected an integer/); + it.each([['-1'], ['-5'], ['abc'], ['2.5']])( + 'rejects the skip %p with one sentence naming the flag and its floor', + async (skip) => { + const failure = await parse(['--skip', skip]).catch((error: unknown) => error); + + expect(failure).toBeInstanceOf(FlagValueError); + expect((failure as FlagValueError).detail).toBe( + `Invalid --skip value "${skip}". Provide a whole number of 0 or more.`, + ); + }, + ); + + it.each([['9'.repeat(400)], ['1' + '0'.repeat(21)], [String(Number.MAX_SAFE_INTEGER + 1)]])( + 'rejects a skip too large to send exactly, rather than letting %p reach the API as Infinity or 1e+21', + async (skip) => { + const failure = await parse(['--skip', skip]).catch((error: unknown) => error); + + expect(failure).toBeInstanceOf(FlagValueError); + expect((failure as FlagValueError).detail).toBe(`Invalid --skip value "${skip}". Provide a whole number of 0 or more.`); + }, + ); + + it('accepts the largest skip that can be sent exactly', async () => { + await expect(parse(['--skip', String(Number.MAX_SAFE_INTEGER)])).resolves.toMatchObject({ skip: Number.MAX_SAFE_INTEGER }); }); it('leaves limit and skip absent when neither is passed so the resolution defaults still apply', async () => { diff --git a/src/core/catalog.ts b/src/core/catalog.ts index cb6a12c9..2bb8fc33 100644 --- a/src/core/catalog.ts +++ b/src/core/catalog.ts @@ -1,14 +1,35 @@ import { Flags } from '@contentstack/cli-utilities'; import { CLIENT_MAX_LIMIT, PROJECT_CONFIG_FILE } from './constants'; +import { FlagValueError } from './errors'; + +const WHOLE_NUMBER = /^-?\d+$/; + +function rangeOf(min: number, max: number | undefined): string { + return max === undefined ? `of ${min} or more` : `from ${min} to ${max}`; +} + +export function wholeNumberFlag(name: string, min: number, max: number | undefined, description: string) { + return Flags.custom({ + description, + parse: async (input: string) => { + const value = input.trim(); + const parsed = Number(value); + + const exact = WHOLE_NUMBER.test(value) && Number.isSafeInteger(parsed); + + if (!exact || parsed < min || (max !== undefined && parsed > max)) { + throw new FlagValueError(`Invalid --${name} value "${input}". Provide a whole number ${rangeOf(min, max)}.`); + } + + return parsed; + }, + })(); +} export const coreFlags = { - limit: Flags.integer({ - min: 1, - max: CLIENT_MAX_LIMIT, - description: `Number of records to fetch (1-${CLIENT_MAX_LIMIT})`, - }), - skip: Flags.integer({ min: 0, description: 'Number of records to skip' }), + limit: wholeNumberFlag('limit', 1, CLIENT_MAX_LIMIT, `Number of records to fetch (1-${CLIENT_MAX_LIMIT})`), + skip: wholeNumberFlag('skip', 0, undefined, 'Number of records to skip'), yes: Flags.boolean({ description: 'Skip the confirmation prompt' }), config: Flags.string({ description: `Path to the local '${PROJECT_CONFIG_FILE}' file` }), 'data-dir': Flags.string({ char: 'd', description: 'Current working directory' }), diff --git a/src/core/launch-command.test.ts b/src/core/launch-command.test.ts index 426b09b6..9c00ca79 100644 --- a/src/core/launch-command.test.ts +++ b/src/core/launch-command.test.ts @@ -581,7 +581,7 @@ describe('LaunchCommand.init config file notice', () => { async function initInFolderHoldingAnOrg( flags: Record, - ): Promise<{ printed: string[]; configFile: string }> { + ): Promise<{ printed: string[]; stderr: string[]; configFile: string }> { const dir = mkdtempSync(join(tmpdir(), 'launch-cli-')); tempDirs.push(dir); writeFileSync(join(dir, PROJECT_CONFIG_FILE), JSON.stringify({ project: { organizationUid: 'org-from-cwd' } })); @@ -597,31 +597,39 @@ describe('LaunchCommand.init config file notice', () => { const printed: string[] = []; const ux: UxLike = { print: (message) => printed.push(message), inquire: async () => undefined as never }; Object.defineProperty(instance, 'ux', { value: ux, configurable: true }); + const stderr: string[] = []; + jest.spyOn(process.stderr, 'write').mockImplementation((chunk: string | Uint8Array) => { + stderr.push(String(chunk)); + return true; + }); await instance.init(); - return { printed, configFile: join(dir, PROJECT_CONFIG_FILE) }; + return { printed, stderr, configFile: join(dir, PROJECT_CONFIG_FILE) }; } - it('prints the notice on stdout when a value came from the config file', async () => { - const { printed, configFile } = await initInFolderHoldingAnOrg({}); + it('writes the notice to stderr, never stdout, when a value came from the config file', async () => { + const { printed, stderr, configFile } = await initInFolderHoldingAnOrg({}); - expect(printed).toEqual([`Using the organization UID from ${configFile}.`]); + expect(stderr).toEqual([`Using the organization UID from ${configFile}.\n`]); + expect(printed).toEqual([]); }); it('colours only the config file path cyan when stdout is a terminal', async () => { const restore = stdoutReportingTTY(true); - const { printed, configFile } = await initInFolderHoldingAnOrg({}); + const { printed, stderr, configFile } = await initInFolderHoldingAnOrg({}); restore(); - expect(printed).toEqual([`Using the organization UID from \u001b[36m${configFile}\u001b[39m.`]); + expect(stderr).toEqual([`Using the organization UID from \u001b[36m${configFile}\u001b[39m.\n`]); + expect(printed).toEqual([]); }); it('prints nothing when every value came from a flag', async () => { - const { printed } = await initInFolderHoldingAnOrg({ org: ORG_FROM_FLAG }); + const { printed, stderr } = await initInFolderHoldingAnOrg({ org: ORG_FROM_FLAG }); expect(printed).toEqual([]); + expect(stderr).toEqual([]); }); }); diff --git a/src/core/launch-command.ts b/src/core/launch-command.ts index 1ced48ad..91997d2f 100644 --- a/src/core/launch-command.ts +++ b/src/core/launch-command.ts @@ -1,3 +1,4 @@ +import { existsSync, statSync } from 'node:fs'; import { resolve as resolvePath } from 'node:path'; import { Command } from '@contentstack/cli-command'; @@ -20,7 +21,7 @@ import type { UxLike } from './prompt'; import { registerSearchList } from './search-list'; import { terminalUx } from './terminal-ux'; import type { FailureOutput } from './failure'; -import { failWith, failureOutputOf, reportFailure } from './failure'; +import { failWith, failureOutputOf, reportFailure, writeToStderr } from './failure'; import type { ServiceContext } from './service-context'; import { buildServiceContext } from './service-context'; @@ -48,7 +49,9 @@ export interface ResolveLaunchContextResult { export async function resolveLaunchContext( args: ResolveLaunchContextArgs, ): Promise> { - const dataDir = stringFlag(args.flags['data-dir']) || process.cwd(); + const namedDataDir = stringFlag(args.flags['data-dir']); + const dataDir = namedDataDir || process.cwd(); + const namedConfig = stringFlag(args.flags.config); const configPath = namedConfig || resolvePath(dataDir, PROJECT_CONFIG_FILE); @@ -64,7 +67,10 @@ export async function resolveLaunchContext( const { resolved, sources } = await resolveInputsTraced(args.inputs, { parsed: args.flags, - projectConfig: projectConfigLoader(new ProjectConfigStore(configPath, Boolean(namedConfig)), Boolean(namedConfig)), + projectConfig: + !namedConfig && namedDataDir && !isFolder(namedDataDir) + ? missingDataDir(namedDataDir) + : projectConfigLoader(new ProjectConfigStore(configPath, Boolean(namedConfig)), Boolean(namedConfig)), services, rules: args.rules, }); @@ -92,6 +98,19 @@ export function projectConfigLoader(store: ProjectConfigStore, named: boolean): }; } +function isFolder(path: string): boolean { + return existsSync(path) && statSync(path).isDirectory(); +} + +function missingDataDir(path: string): () => ProjectConfig { + return () => { + throw new UsageError( + `No folder found at '${resolvePath(path)}', so there is no ${PROJECT_CONFIG_FILE} to read. ` + + 'Pass --data-dir with a folder that exists.', + ); + }; +} + function stringFlag(value: unknown): string | undefined { return typeof value === 'string' ? value : undefined; } @@ -156,7 +175,7 @@ export abstract class LaunchCommand extends Com this.configPath = configPath; if (configNotice !== undefined) { - this.ux.print(configNotice); + writeToStderr(configNotice); } } diff --git a/src/core/project-config.test.ts b/src/core/project-config.test.ts index 174543e6..fed63034 100644 --- a/src/core/project-config.test.ts +++ b/src/core/project-config.test.ts @@ -92,12 +92,19 @@ describe('ProjectConfigStore.load', () => { expect(new ProjectConfigStore('/nope/.cs-launch.json').load()).toEqual({}); }); - it('returns an empty object when the file is not valid JSON', () => { - const path = tempPath(); - writeFileSync(path, 'not json'); + it.each([[false], [true]])( + 'refuses a file that exists but is not valid JSON, naming it, when required is %p', + (required) => { + const path = tempPath(); + writeFileSync(path, 'not json'); - expect(new ProjectConfigStore(path).load()).toEqual({}); - }); + expect(() => new ProjectConfigStore(path, required).load()).toThrow( + new UsageError( + `The config file at '${path}' is not valid JSON. Fix or delete it, or pass the missing flags.`, + ), + ); + }, + ); it('uses the shared block when several branch blocks name the same project', () => { const store = storeFor({ @@ -180,14 +187,6 @@ describe('ProjectConfigStore.load', () => { expect(storeFor({ main: null }).load()).toEqual({}); }); - it('returns an empty object when the file root is an array', () => { - expect(storeFor([{ uid: 'p1', organizationUid: 'org1' }]).load()).toEqual({}); - }); - - it('returns an empty object when the file root is an empty array', () => { - expect(storeFor([]).load()).toEqual({}); - }); - it('raises a usage error when every branch block is an array', () => { const store = storeFor({ main: [{ uid: 'p1' }], staging: [{ uid: 'p1' }] }); @@ -199,9 +198,18 @@ describe('ProjectConfigStore.load', () => { expect(storeFor({}).load()).toEqual({}); }); - it.each([[null], [42], ['string'], [true]])('returns an empty object when the file contains %p', (contents) => { - expect(storeFor(contents).load()).toEqual({}); - }); + it.each([[[{ uid: 'p1', organizationUid: 'org1' }]], [[]], [null], [42], ['string'], [true]])( + 'refuses a file whose contents %p are not a project config, naming it', + (contents) => { + const store = storeFor(contents); + + expect(() => store.load()).toThrow( + new UsageError( + `The config file at '${store.path}' does not hold a project config. Fix or delete it, or pass the missing flags.`, + ), + ); + }, + ); }); describe('ProjectConfigStore.save', () => { diff --git a/src/core/project-config.ts b/src/core/project-config.ts index 49eba628..4e029712 100644 --- a/src/core/project-config.ts +++ b/src/core/project-config.ts @@ -166,7 +166,11 @@ export class ProjectConfigStore { return this.unusable(`No config file found at '${this.path}'. Pass --config with a path that exists.`); } - return typeof read === 'string' ? this.unusable(read) : read; + if (typeof read === 'string') { + throw new UsageError(`${read} Fix or delete it, or pass the missing flags.`); + } + + return read; } private read(): Blocks | string | undefined { diff --git a/src/core/render.test.ts b/src/core/render.test.ts index 847ac1f1..ec013777 100644 --- a/src/core/render.test.ts +++ b/src/core/render.test.ts @@ -1,6 +1,11 @@ -import { renderPagination, renderTable } from './render'; +import { randomBytes } from 'node:crypto'; + +import { renderPagination, renderTable, wrapCell } from './render'; import type { UxLike } from './prompt'; +const FIRST_UID = randomBytes(12).toString('hex'); +const SECOND_UID = randomBytes(12).toString('hex'); + function fakeUx() { const lines: string[] = []; const ux: UxLike = { @@ -50,7 +55,7 @@ describe('renderTable', () => { it('prints the no-rows placeholder in yellow when the output is a terminal', () => { const { ux, lines } = fakeUx(); - renderTable(ux, [{ header: 'UID', value: (row: { uid: string }) => row.uid }], [], undefined, undefined, true); + renderTable(ux, [{ header: 'UID', value: (row: { uid: string }) => row.uid }], [], undefined, true); expect(lines).toEqual(['\u001b[33mNo records found.\u001b[39m']); }); @@ -162,39 +167,215 @@ describe('renderTable', () => { expect(lines[5]).toBe('\u2502 a2 \u2502 b2 \u2502 c2 \u2502'); }); - it('shrinks only the first column, with an ellipsis, when the box is wider than the terminal', () => { + it('shrinks the widest column first and wraps its text onto extra lines rather than cutting it', () => { const { ux, lines } = fakeUx(); renderTable( ux, [ - { header: 'NAME', value: (row: { name: string; uid: string }) => row.name }, - { header: 'UID', value: (row: { name: string; uid: string }) => row.uid }, + { header: 'NAME', value: (row: { name: string; url: string }) => row.name }, + { header: 'URL', value: (row: { name: string; url: string }) => row.url }, ], - [{ name: 'a-long-project-name', uid: 'p1' }], - 24, + [{ name: 'staging', url: 'https://staging-site.contentstackapps.com' }], + 44, + ); + + expect(lines.slice(3, 5)).toEqual([ + '\u2502 staging \u2502 https://staging-site.conte \u2502', + '\u2502 \u2502 ntstackapps.com \u2502', + ]); + expect(lines.map((line) => [...line].length)).toEqual([44, 44, 44, 44, 44, 44]); + expect(lines.join('')).not.toContain('\u2026'); + }); + + it('breaks a wrapped cell at the last space that fits, and only hard-breaks a word longer than the cell', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [{ header: 'NOTE', value: (row: { note: string }) => row.note }], + [{ note: 'one two three abcdefghijklmnop' }], + 16, ); - expect(lines[1]).toBe('\u2502 NAME \u2502 UID \u2502'); - expect(lines[3]).toBe('\u2502 a-long-pr\u2026 \u2502 p1 \u2502'); - expect(lines.every((line) => [...line].length === 24)).toBe(true); + expect(lines.slice(3, -1)).toEqual([ + '\u2502 one two \u2502', + '\u2502 three \u2502', + '\u2502 abcdefghij \u2502', + '\u2502 klmnop \u2502', + ]); }); - it('stops shrinking at the first header, drawing wider than the terminal rather than erasing the column', () => { + it('shares the shrinking out, so the long URL gives way before the short name is touched', () => { const { ux, lines } = fakeUx(); renderTable( ux, [ - { header: 'NAME', value: (row: { name: string; uid: string }) => row.name }, - { header: 'UID', value: (row: { name: string; uid: string }) => row.uid }, + { header: 'NAME', value: (row: { name: string; url: string }) => row.name }, + { header: 'URL', value: (row: { name: string; url: string }) => row.url }, ], - [{ name: 'a-long-project-name', uid: 'p1' }], - 8, + [{ name: 'production-eu', url: 'https://production-eu.contentstackapps.com' }], + 50, + ); + + expect(lines[3]).toContain('\u2502 production-eu \u2502'); + }); + + it('never narrows a column below its minWidth, so a UID stays whole on one line', () => { + const { ux, lines } = fakeUx(); + const uid = FIRST_UID; + + renderTable( + ux, + [ + { header: 'UID', value: (row: { uid: string; note: string }) => row.uid, minWidth: 24 }, + { header: 'NOTE', value: (row: { uid: string; note: string }) => row.note }, + ], + [{ uid, note: 'a note long enough to need wrapping' }], + 50, + ); + + expect(lines[3]).toContain(`\u2502 ${uid} \u2502`); + expect(lines.slice(4, -1).every((line) => line.startsWith(`\u2502 ${' '.repeat(24)} \u2502`))).toBe(true); + expect(lines.map((line) => [...line].length).every((width) => width === 50)).toBe(true); + }); + + it('prints each record as a stacked list of labelled lines when the columns cannot fit even at their floors', () => { + const { ux, lines } = fakeUx(); + const columns = [ + { header: 'DEPLOYMENT UID', value: (row: { uid: string; status: string }) => row.uid, minWidth: 24 }, + { header: 'STATUS', value: (row: { uid: string; status: string }) => row.status }, + ]; + + renderTable( + ux, + columns, + [ + { uid: FIRST_UID, status: 'LIVE' }, + { uid: SECOND_UID, status: 'FAILED' }, + ], + 40, + ); + + expect(lines).toEqual([ + `DEPLOYMENT UID ${FIRST_UID}`, + 'STATUS LIVE', + '', + `DEPLOYMENT UID ${SECOND_UID}`, + 'STATUS FAILED', + ]); + }); + + it('wraps a long stacked value under itself, indented past the labels, so no line outgrows the terminal', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [ + { header: 'UID', value: (row: { uid: string; url: string }) => row.uid, minWidth: 24 }, + { header: 'URL', value: (row: { uid: string; url: string }) => row.url, minWidth: 24 }, + ], + [{ uid: FIRST_UID, url: 'https://staging-site.contentstackapps.com' }], + 30, + ); + + expect(lines).toEqual([`UID ${FIRST_UID}`, 'URL https://staging-site.cont', ' entstackapps.com']); + }); + + it('prints a detail table as plain field-and-value lines, not FIELD/VALUE records, when it cannot fit', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [ + { header: 'FIELD', value: (row: { field: string; value: string }) => row.field, label: true }, + { header: 'VALUE', value: (row: { field: string; value: string }) => row.value, minWidth: 24 }, + ], + [ + { field: 'ENVIRONMENT UID', value: FIRST_UID }, + { field: 'NAME', value: 'staging' }, + ], + 44, + true, ); - expect(lines[1]).toBe('\u2502 NAME \u2502 UID \u2502'); - expect(lines[3]).toBe('\u2502 a-l\u2026 \u2502 p1 \u2502'); + expect(lines).toEqual([`ENVIRONMENT UID ${FIRST_UID}`, 'NAME staging']); + }); + + it('never shrinks a label column, so a field name is not broken mid-word', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [ + { header: 'FIELD', value: (row: { field: string; value: string }) => row.field, label: true }, + { header: 'VALUE', value: (row: { field: string; value: string }) => row.value }, + ], + [{ field: 'CONTENTSTACK AUTH', value: 'enabled for every visitor of the site' }], + 45, + ); + + expect(lines[3]).toBe('\u2502 CONTENTSTACK AUTH \u2502 enabled for every \u2502'); + expect(lines.map((line) => [...line].length).every((width) => width === 45)).toBe(true); + }); + + it('moves a stacked value onto its own indented line when it would not fit beside the label', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [ + { header: 'ENVIRONMENT UID', value: (row: { uid: string; name: string }) => row.uid, minWidth: 24 }, + { header: 'NAME', value: (row: { uid: string; name: string }) => row.name, minWidth: 24 }, + ], + [{ uid: FIRST_UID, name: 'staging' }], + 40, + ); + + expect(lines).toEqual(['ENVIRONMENT UID', ` ${FIRST_UID}`, 'NAME', ' staging']); + expect(lines.every((line) => [...line].length <= 40)).toBe(true); + }); + + it('bolds the stacked labels on a terminal and leaves the values plain', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [{ header: 'UID', value: (row: { uid: string }) => row.uid, minWidth: 24 }], + [{ uid: FIRST_UID }], + 29, + true, + ); + + expect(lines).toEqual([`\u001b[1mUID\u001b[22m ${FIRST_UID}`]); + }); + + it('stops shrinking a plain column at ten characters and stacks rather than squeezing it further', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [{ header: 'NAME', value: (row: { name: string }) => row.name }], + [{ name: 'abcdefghijklmnop' }], + 15, + ); + + expect(lines).toEqual(['NAME', ' abcdefghijklmnop']); + }); + + it('keeps a column at its header width when that is wider than ten characters', () => { + const { ux, lines } = fakeUx(); + + renderTable( + ux, + [{ header: 'ENVIRONMENT NAME', value: (row: { name: string }) => row.name }], + [{ name: 'a-very-long-environment-name' }], + 22, + ); + + expect(lines[1]).toBe('\u2502 ENVIRONMENT NAME \u2502'); + expect(lines.slice(3, -1)).toEqual(['\u2502 a-very-long-envi \u2502', '\u2502 ronment-name \u2502']); }); it.each([ @@ -229,35 +410,29 @@ describe('renderTable', () => { expect(lines[3]).toBe('\u2502 a-long-project-name \u2502'); }); - it('measures and truncates by character, so an astral cell never splits into a replacement glyph', () => { + it('measures and wraps by character, so an astral cell never splits into a replacement glyph', () => { const { ux, lines } = fakeUx(); - renderTable(ux, [{ header: 'NAME', value: (row: { name: string }) => row.name }], [{ name: '\u{1f600}'.repeat(6) }], 10); + renderTable( + ux, + [{ header: 'NAME', value: (row: { name: string }) => row.name }], + [{ name: '\u{1f600}'.repeat(12) }], + 16, + ); - expect(lines[3]).toBe('\u2502 \u{1f600}\u{1f600}\u{1f600}\u2026 \u2502'); - expect(lines.map((line) => [...line].length)).toEqual([10, 10, 10, 10, 10]); + expect(lines.slice(3, -1)).toEqual([ + `\u2502 ${'\u{1f600}'.repeat(10)} \u2502`, + `\u2502 ${'\u{1f600}'.repeat(2)} \u2502`, + ]); + expect(lines.map((line) => [...line].length).every((width) => width === 16)).toBe(true); expect(lines.join('')).not.toContain('\ufffd'); }); - it('shrinks the column it is told to and leaves every other one whole', () => { - const { ux, lines } = fakeUx(); - const columns = [ - { header: 'UID', value: (row: { uid: string; note: string }) => row.uid }, - { header: 'NOTE', value: (row: { uid: string; note: string }) => row.note }, - ]; - const rows = [{ uid: 'project-uid-of-24-chars!', note: 'a note long enough to need trimming' }]; - - renderTable(ux, columns, rows, 50, 1); - - expect(lines[3]).toBe('\u2502 project-uid-of-24-chars! \u2502 a note long en\u2026 \u2502'); - expect(lines.map((line) => [...line].length)).toEqual([50, 50, 50, 50, 50]); - }); - it('bolds the header cells on a terminal, after padding them, and leaves the data rows alone', () => { const { ux, lines } = fakeUx(); const columns = [{ header: 'NAME', value: (row: { name: string }) => row.name }]; - renderTable(ux, columns, [{ name: 'a-long-name' }], undefined, undefined, true); + renderTable(ux, columns, [{ name: 'a-long-name' }], undefined, true); expect(lines[1]).toBe('\u2502 \u001b[1mNAME \u001b[22m \u2502'); expect(lines[3]).toBe('\u2502 a-long-name \u2502'); @@ -300,6 +475,20 @@ describe('renderTable', () => { }); }); +describe('wrapCell', () => { + it('starts a continuation line at the next word, dropping the run of spaces it broke on', () => { + expect(wrapCell('abcd ef', 4)).toEqual(['abcd', 'ef']); + }); + + it('adds no empty line when the text ends in spaces at a break', () => { + expect(wrapCell('abcd ', 4)).toEqual(['abcd']); + }); + + it('returns one empty line for an empty cell', () => { + expect(wrapCell('', 4)).toEqual(['']); + }); +}); + describe('renderPagination', () => { it('reports the window and the total', () => { const { ux, lines } = fakeUx(); diff --git a/src/core/render.ts b/src/core/render.ts index f7a134d8..1431d699 100644 --- a/src/core/render.ts +++ b/src/core/render.ts @@ -11,8 +11,12 @@ export interface Pagination { export interface TableColumn { header: string; value: (row: T) => string; + minWidth?: number; + label?: boolean; } +export const UID_WIDTH = 24; + const UNPRINTABLE = '-'; function cellText(value: unknown): string { @@ -54,13 +58,13 @@ const BOX = { bottomRight: '\u2518', } as const; -const ELLIPSIS = '\u2026'; const CELL_PAD = ' '; const CELL_PADDING = CELL_PAD.length * 2; const EDGE_PADDING = 2 + CELL_PADDING; const JOIN_PADDING = 1 + CELL_PADDING; -const NARROWEST_CELL = 1; -const FIRST_COLUMN = 0; +const READABLE_CELL = 10; +const STACKED_GAP = ' '; +const OWN_LINE_INDENT = ' '; function unitsOf(text: string): string[] { return [...text]; @@ -74,49 +78,166 @@ function ruleOf(widths: number[], left: string, join: string, right: string, fil return left + widths.map((width) => fill.repeat(width + CELL_PADDING)).join(join) + right; } -function fitCell(text: string, width: number): string { - const units = unitsOf(text); +function padCell(text: string, width: number): string { + return text + ' '.repeat(Math.max(0, width - widthOf(text))); +} + +function breakAt(units: string[], width: number): number { + const space = units.lastIndexOf(' ', width); + + return space > 0 ? space + 1 : width; +} + +export function wrapCell(text: string, width: number): string[] { + const lines: string[] = []; + let units = unitsOf(text); + + while (units.length > width) { + const cut = breakAt(units.slice(0, width + 1), width); + lines.push(units.slice(0, cut).join('').trimEnd()); + units = units.slice(cut); + + while (units[0] === ' ') { + units.shift(); + } + } - if (units.length > width) { - return `${units.slice(0, width - 1).join('')}${ELLIPSIS}`; + if (units.length > 0 || lines.length === 0) { + lines.push(units.join('')); } - return text + ' '.repeat(width - units.length); + return lines; } function joinCells(fitted: string[]): string { return `${BOX.vertical}${CELL_PAD}${fitted.join(`${CELL_PAD}${BOX.vertical}${CELL_PAD}`)}${CELL_PAD}${BOX.vertical}`; } -function rowOf(cells: string[], widths: number[]): string { - return joinCells(cells.map((cell, index) => fitCell(cell, widths[index]))); +function rowLinesOf(cells: string[], widths: number[]): string[] { + const wrapped = cells.map((cell, index) => wrapCell(cell, widths[index])); + const height = Math.max(...wrapped.map((lines) => lines.length)); + + return Array.from({ length: height }, (_, line) => + joinCells(wrapped.map((lines, index) => padCell(lines[line] ?? '', widths[index]))), + ); } function headerRowOf(headers: string[], widths: number[], outputIsTTY: boolean): string { - return joinCells(headers.map((header, index) => styled(fitCell(header, widths[index]), 'bold', outputIsTTY))); + return joinCells(headers.map((header, index) => styled(padCell(header, widths[index]), 'bold', outputIsTTY))); } -function fittedWidths( - widths: number[], - floors: number[], - flexible: number, - available: number | undefined, -): number[] { - if (available === undefined) { - return widths; +function drawnWidth(widths: number[]): number { + return widths.reduce((sum, width) => sum + width, 0) + EDGE_PADDING + (widths.length - 1) * JOIN_PADDING; +} + +function widestShrinkable(widths: number[], floors: number[]): number { + let widest = -1; + + widths.forEach((width, index) => { + if (width > floors[index] && (widest === -1 || width > widths[widest])) { + widest = index; + } + }); + + return widest; +} + +function fittedWidths(natural: number[], floors: number[], available: number): number[] | undefined { + const widths = [...natural]; + + while (drawnWidth(widths) > available) { + const widest = widestShrinkable(widths, floors); + + if (widest === -1) { + return undefined; + } + + widths[widest] -= 1; } - const chrome = EDGE_PADDING + (widths.length - 1) * JOIN_PADDING; - const drawn = widths.reduce((sum, width) => sum + width, 0) + chrome; + return widths; +} - if (drawn <= available) { - return widths; +function floorOf(column: TableColumn, natural: number): number { + if (column.label === true) { + return natural; } - const fitted = [...widths]; - fitted[flexible] = Math.max(NARROWEST_CELL, floors[flexible], widths[flexible] - (drawn - available)); + return Math.min(natural, Math.max(widthOf(column.header), column.minWidth ?? READABLE_CELL)); +} + +function printLabelled( + ux: UxLike, + pairs: [string, string][], + available: number, + boldLabels: boolean, +): void { + const labelWidth = Math.max(...pairs.map(([label]) => widthOf(label))); + const indent = ' '.repeat(labelWidth + STACKED_GAP.length); + const besideLabel = available - indent.length >= UID_WIDTH; + + pairs.forEach(([label, value]) => { + const shownLabel = styled(besideLabel ? padCell(label, labelWidth) : label, 'bold', boldLabels); + + if (besideLabel) { + const [first, ...rest] = wrapCell(value, available - indent.length); - return fitted; + ux.print(`${shownLabel}${STACKED_GAP}${first}`); + rest.forEach((line) => ux.print(`${indent}${line}`)); + return; + } + + ux.print(shownLabel); + wrapCell(value, Math.max(available - OWN_LINE_INDENT.length, UID_WIDTH)).forEach((line) => + ux.print(`${OWN_LINE_INDENT}${line}`), + ); + }); +} + +function renderStacked( + ux: UxLike, + headers: string[], + cells: string[][], + available: number, + outputIsTTY: boolean, +): void { + cells.forEach((rowCells, index) => { + if (index > 0) { + ux.print(''); + } + + printLabelled( + ux, + rowCells.map((cell, column): [string, string] => [headers[column], cell]), + available, + outputIsTTY, + ); + }); +} + +function renderDetailLines(ux: UxLike, cells: string[][], available: number): void { + printLabelled( + ux, + cells.map(([label, value]): [string, string] => [label, value]), + available, + false, + ); +} + +function drawBox(ux: UxLike, headers: string[], cells: string[][], widths: number[], outputIsTTY: boolean): void { + ux.print(ruleOf(widths, BOX.topLeft, BOX.topJoin, BOX.topRight, BOX.horizontal)); + ux.print(headerRowOf(headers, widths, outputIsTTY)); + ux.print(ruleOf(widths, BOX.midLeft, BOX.midJoin, BOX.midRight, BOX.horizontal)); + + cells.forEach((rowCells, index) => { + if (index > 0) { + ux.print(ruleOf(widths, BOX.midLeft, BOX.midJoin, BOX.midRight, BOX.dotted)); + } + + rowLinesOf(rowCells, widths).forEach((line) => ux.print(line)); + }); + + ux.print(ruleOf(widths, BOX.bottomLeft, BOX.bottomJoin, BOX.bottomRight, BOX.horizontal)); } export function renderTable( @@ -124,7 +245,6 @@ export function renderTable( columns: TableColumn[], rows: T[], available?: number, - flexible: number = FIRST_COLUMN, outputIsTTY = false, ): void { if (rows.length === 0) { @@ -141,21 +261,29 @@ export function renderTable( const natural = columns.map((column, index) => Math.max(widthOf(column.header), ...cells.map((rowCells) => widthOf(rowCells[index]))), ); - const widths = fittedWidths(natural, headers.map(widthOf), flexible, available); - ux.print(ruleOf(widths, BOX.topLeft, BOX.topJoin, BOX.topRight, BOX.horizontal)); - ux.print(headerRowOf(headers, widths, outputIsTTY)); - ux.print(ruleOf(widths, BOX.midLeft, BOX.midJoin, BOX.midRight, BOX.horizontal)); + if (available === undefined) { + drawBox(ux, headers, cells, natural, outputIsTTY); + return; + } - cells.forEach((rowCells, index) => { - if (index > 0) { - ux.print(ruleOf(widths, BOX.midLeft, BOX.midJoin, BOX.midRight, BOX.dotted)); - } + const widths = fittedWidths( + natural, + columns.map((column, index) => floorOf(column, natural[index])), + available, + ); - ux.print(rowOf(rowCells, widths)); - }); + if (widths === undefined && columns.length === 2 && columns[0].label === true) { + renderDetailLines(ux, cells, available); + return; + } - ux.print(ruleOf(widths, BOX.bottomLeft, BOX.bottomJoin, BOX.bottomRight, BOX.horizontal)); + if (widths === undefined) { + renderStacked(ux, headers, cells, available, outputIsTTY); + return; + } + + drawBox(ux, headers, cells, widths, outputIsTTY); } export function renderPagination(ux: UxLike, pagination: Pagination | undefined, rowsPrinted: number): void { diff --git a/src/deployments/deployment.presenter.ts b/src/deployments/deployment.presenter.ts index 995eb0a9..39a38322 100644 --- a/src/deployments/deployment.presenter.ts +++ b/src/deployments/deployment.presenter.ts @@ -1,6 +1,7 @@ import { stripVTControlCharacters } from 'node:util'; import type { TableColumn } from '../core/render'; +import { UID_WIDTH } from '../core/render'; import { styled } from '../core/style'; import { webUrlOf } from '../core/url'; import { isAbsent, withoutControlCharacters } from '../core/values'; @@ -294,7 +295,7 @@ function shortCommit(value: string | undefined): string { export function deploymentColumns(showGit: boolean): TableColumn[] { const columns: TableColumn[] = [ - { header: 'DEPLOYMENT UID', value: (deployment) => text(deployment.uid) }, + { header: 'DEPLOYMENT UID', value: (deployment) => text(deployment.uid), minWidth: UID_WIDTH }, { header: 'STATUS', value: (deployment) => text(deployment.status) }, ]; @@ -312,12 +313,10 @@ export function deploymentColumns(showGit: boolean): TableColumn[] { } export const DEPLOYMENT_DETAIL_COLUMNS: TableColumn[] = [ - { header: 'FIELD', value: (row) => row.field }, - { header: 'VALUE', value: (row) => row.value }, + { header: 'FIELD', value: (row) => row.field, label: true }, + { header: 'VALUE', value: (row) => row.value, minWidth: UID_WIDTH }, ]; -export const DEPLOYMENT_VALUE_COLUMN = 1; - export function deploymentVariablesSummary(deployment: Deployment, scope: DeploymentScope): string { const count = Array.isArray(deployment.environmentVariables) ? deployment.environmentVariables.length : 0; diff --git a/src/environments/environment.presenter.test.ts b/src/environments/environment.presenter.test.ts index 8dc0299c..aeb785ba 100644 --- a/src/environments/environment.presenter.test.ts +++ b/src/environments/environment.presenter.test.ts @@ -2,7 +2,6 @@ import { ENVIRONMENT_COLUMNS, ENVIRONMENT_DELETE_QUESTION, ENVIRONMENT_DETAIL_COLUMNS, - ENVIRONMENT_VALUE_COLUMN, environmentColumns, environmentDeletedLine, environmentAlreadyMatchesLine, @@ -10,6 +9,7 @@ import { environmentNoChangesLine, environmentNotDeletedLine, } from './environment.presenter'; +import { UID_WIDTH } from '../core/render'; const FULL = { uid: 'e1', @@ -161,13 +161,14 @@ describe('environmentDetailRows', () => { }); describe('ENVIRONMENT_DETAIL_COLUMNS', () => { - it('draws a FIELD and a VALUE column and lets the VALUE column flex', () => { + it('draws a FIELD label column and a VALUE column wide enough for a whole UID', () => { expect(ENVIRONMENT_DETAIL_COLUMNS.map((column) => column.header)).toEqual(['FIELD', 'VALUE']); expect(ENVIRONMENT_DETAIL_COLUMNS.map((column) => column.value({ field: 'NAME', value: 'production' }))).toEqual([ 'NAME', 'production', ]); - expect(ENVIRONMENT_VALUE_COLUMN).toBe(1); + expect(ENVIRONMENT_DETAIL_COLUMNS.map((column) => column.minWidth)).toEqual([undefined, UID_WIDTH]); + expect(ENVIRONMENT_DETAIL_COLUMNS.map((column) => column.label)).toEqual([true, undefined]); }); }); diff --git a/src/environments/environment.presenter.ts b/src/environments/environment.presenter.ts index de32a074..8867413d 100644 --- a/src/environments/environment.presenter.ts +++ b/src/environments/environment.presenter.ts @@ -1,4 +1,5 @@ import type { TableColumn } from '../core/render'; +import { UID_WIDTH } from '../core/render'; import { styled } from '../core/style'; import { firstDeploymentFailureMessage } from '../deployments/deployment.presenter'; import { isAbsent } from '../core/values'; @@ -32,7 +33,7 @@ export const ENVIRONMENT_COLUMNS: TableColumn[] = [ { header: 'BRANCH', value: (environment) => text(environment.gitBranch) }, { header: 'URL', value: (environment) => text(urlsOf(environment)[0]) }, { header: 'UPDATED', value: (environment) => text(environment.updatedAt) }, - { header: 'ENVIRONMENT UID', value: (environment) => text(environment.uid) }, + { header: 'ENVIRONMENT UID', value: (environment) => text(environment.uid), minWidth: UID_WIDTH }, ]; export function environmentColumns(showBranch: boolean): TableColumn[] { @@ -40,12 +41,10 @@ export function environmentColumns(showBranch: boolean): TableColumn[] = [ - { header: 'FIELD', value: (row) => row.field }, - { header: 'VALUE', value: (row) => row.value }, + { header: 'FIELD', value: (row) => row.field, label: true }, + { header: 'VALUE', value: (row) => row.value, minWidth: UID_WIDTH }, ]; -export const ENVIRONMENT_VALUE_COLUMN = 1; - export function environmentDetailRows(environment: Environment, showBranch = true): DetailRow[] { const rows: DetailRow[] = [ { field: 'ENVIRONMENT UID', value: text(environment.uid) }, diff --git a/src/projects/project.presenter.ts b/src/projects/project.presenter.ts index 689e3bb6..de84cfdc 100644 --- a/src/projects/project.presenter.ts +++ b/src/projects/project.presenter.ts @@ -1,5 +1,6 @@ import type { LaunchError } from '../core/errors'; import type { TableColumn } from '../core/render'; +import { UID_WIDTH } from '../core/render'; import { styled } from '../core/style'; import { firstDeploymentFailureMessage } from '../deployments/deployment.presenter'; import { LaunchApiError } from '../transport/errors'; @@ -8,7 +9,7 @@ import type { Project } from './types'; export const PROJECT_COLUMNS: TableColumn[] = [ { header: 'NAME', value: (project) => project.name ?? '-' }, { header: 'TYPE', value: (project) => project.projectType ?? '-' }, - { header: 'PROJECT UID', value: (project) => project.uid ?? '-' }, + { header: 'PROJECT UID', value: (project) => project.uid ?? '-', minWidth: UID_WIDTH }, ]; export const PROJECT_DETAIL_COLUMNS: TableColumn[] = [ @@ -16,8 +17,6 @@ export const PROJECT_DETAIL_COLUMNS: TableColumn[] = [ { header: 'DESCRIPTION', value: (project) => project.description ?? '-' }, ]; -export const PROJECT_DESCRIPTION_COLUMN = PROJECT_DETAIL_COLUMNS.length - 1; - export const PROJECT_DELETE_QUESTION = 'Are you sure you want to delete this project?'; export const PROJECT_DELETED = '\u2714 Project deleted successfully.'; diff --git a/src/variables/variable.chooser.ts b/src/variables/variable.chooser.ts index e5be2165..0cb488f1 100644 --- a/src/variables/variable.chooser.ts +++ b/src/variables/variable.chooser.ts @@ -46,7 +46,7 @@ async function askForTyped(services: ServiceContext, io: VariableIo): Promise[]; + rows: unknown[]; + uids: string[]; +} + +const CASES: Case[] = [ + { name: 'env:list', columns: environmentColumns(true) as never, rows: [environment], uids: [ENVIRONMENT_UID] }, + { + name: 'env:get', + columns: ENVIRONMENT_DETAIL_COLUMNS as never, + rows: environmentDetailRows(environment), + uids: [ENVIRONMENT_UID], + }, + { name: 'deployments:list', columns: deploymentColumns(true) as never, rows: [deployment], uids: [DEPLOYMENT_UID] }, + { + name: 'deployments:get', + columns: DEPLOYMENT_DETAIL_COLUMNS as never, + rows: deploymentDetailRows(deployment, true, { org: ORG_UID, project: PROJECT_UID, environment: ENVIRONMENT_UID }), + uids: [DEPLOYMENT_UID], + }, + { name: 'projects:list', columns: PROJECT_COLUMNS as never, rows: [project], uids: [PROJECT_UID] }, + { name: 'projects:get', columns: PROJECT_DETAIL_COLUMNS as never, rows: [project], uids: [PROJECT_UID] }, +]; + +function draw(table: Case, width: number): string[] { + const lines: string[] = []; + const ux: UxLike = { print: (line) => lines.push(line), inquire: async () => undefined as never }; + + renderTable(ux, table.columns, table.rows as never[], width); + + return lines; +} + +const WIDTHS = [30, 40, 45, 50, 60, 80, 100]; + +const DETAIL_CASES = CASES.filter((table) => (table.columns[0] as { label?: boolean }).label === true); + +describe('guard: tables fit a narrow terminal without cutting a UID', () => { + it.each(CASES.flatMap((table) => WIDTHS.map((width) => [table.name, width, table] as const)))( + '%s at %i columns draws no line wider than the terminal and prints every UID whole on one line', + (_name, width, table) => { + const lines = draw(table, width); + const tooWide = lines.filter((line) => [...line].length > width); + + expect(tooWide).toEqual([]); + table.uids.forEach((uid) => expect(lines.some((line) => line.includes(uid))).toBe(true)); + expect(lines.join('\n')).not.toContain('…'); + }, + ); + + it.each(DETAIL_CASES.flatMap((table) => WIDTHS.map((width) => [table.name, width, table] as const)))( + '%s at %i columns prints every field label whole on one line and never as a FIELD/VALUE record', + (_name, width, table) => { + const lines = draw(table, width); + + (table.rows as { field: string }[]).forEach((row) => + expect(lines.some((line) => line.includes(row.field))).toBe(true), + ); + expect(lines.some((line) => /^FIELD\s/.test(line))).toBe(false); + }, + ); +}); diff --git a/test/guards/whole-number-flags.test.ts b/test/guards/whole-number-flags.test.ts new file mode 100644 index 00000000..60f731e5 --- /dev/null +++ b/test/guards/whole-number-flags.test.ts @@ -0,0 +1,11 @@ +import { occurrences, productionSources } from '../support/sources'; + +describe('guard: number flags give one readable sentence when the value is wrong', () => { + it('declares no Flags.integer in src, so a bad number never prints oclif\'s "Parsing --flag" text', () => { + const offenders = productionSources() + .flatMap((source) => occurrences(source, /\bFlags\.integer\s*\(/)) + .map((hit) => `src/${hit.path}:${hit.line} ${hit.text}`); + + expect(offenders).toEqual([]); + }); +}); diff --git a/test/integration/projects-command-flows.test.ts b/test/integration/projects-command-flows.test.ts index d7908e84..8e63be54 100644 --- a/test/integration/projects-command-flows.test.ts +++ b/test/integration/projects-command-flows.test.ts @@ -74,6 +74,63 @@ describe('integration: end-to-end command flows', () => { nock.restore(); }); + it('refuses a --data-dir that does not exist, naming it, instead of reporting a missing --org, and sends nothing', async () => { + useSession(basicSession()); + const missing = join(mkdtempSync(join(tmpdir(), 'launch-flow-')), 'no-such-folder'); + tempDirs.push(join(missing, '..')); + const scope = nock(LAUNCH_HUB_URL).get(/.*/).reply(200, listFixture); + + const { error, stdout, stderr } = await runLaunch(['launch:projects:list', '--data-dir', missing]); + + expect(error?.oclif?.exit).toBe(2); + expect(stdout).toBe(''); + expect(stderr).toBe( + `error: No folder found at '${missing}', so there is no ${PROJECT_CONFIG_FILE} to read. ` + + 'Pass --data-dir with a folder that exists.\n', + ); + expect(scope.isDone()).toBe(false); + }); + + it('lets a missing --data-dir pass when the flags already supply everything the config file would', async () => { + useSession(basicSession()); + const missing = join(mkdtempSync(join(tmpdir(), 'launch-flow-')), 'no-such-folder'); + tempDirs.push(join(missing, '..')); + const scope = nock(LAUNCH_HUB_URL) + .matchHeader('x-organization-uid', ORG_UID) + .get('/manage/projects') + .query(true) + .reply(200, listFixture); + + const { error } = await runLaunch(['launch:projects:list', '--org', ORG_UID, '--data-dir', missing]); + + expect(error).toBeUndefined(); + expect(scope.isDone()).toBe(true); + }); + + it.each([ + ['not valid JSON', '{ "project": ', 'is not valid JSON.'], + ['an array', '[]', 'does not hold a project config.'], + ])( + 'refuses a found %s config file, naming it, instead of reporting a missing --org', + async (_kind, contents, reason) => { + useSession(basicSession()); + const dir = mkdtempSync(join(tmpdir(), 'launch-flow-')); + tempDirs.push(dir); + const path = join(dir, PROJECT_CONFIG_FILE); + writeFileSync(path, contents); + const scope = nock(LAUNCH_HUB_URL).get(/.*/).reply(200, listFixture); + + const { error, stdout, stderr } = await runLaunch(['launch:projects:list', '--data-dir', dir]); + + expect(error?.oclif?.exit).toBe(2); + expect(stdout).toBe(''); + expect(stderr).toBe( + `error: The config file at '${path}' ${reason} Fix or delete it, or pass the missing flags.\n`, + ); + expect(scope.isDone()).toBe(false); + }, + ); + it('reads the organization and the project out of a project folder config with no flags but the data dir', async () => { useSession(basicSession()); const { dir } = projectFolder({ project: { organizationUid: ORG_UID, uid: PROJECT_UID } }); @@ -85,13 +142,13 @@ describe('integration: end-to-end command flows', () => { .times(2) .reply(200, getFixture); - const { error, stdout } = await runLaunch(['launch:projects:get', '--data-dir', dir]); + const { error, stdout, stderr } = await runLaunch(['launch:projects:get', '--data-dir', dir]); expect(error).toBeUndefined(); expect(scope.isDone()).toBe(true); + expect(stderr).toBe(`Using the organization and project UIDs from ${join(dir, PROJECT_CONFIG_FILE)}.\n`); expect(stdout).toBe( [ - `Using the organization and project UIDs from ${join(dir, PROJECT_CONFIG_FILE)}.`, '\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510', '\u2502 NAME \u2502 TYPE \u2502 PROJECT UID \u2502 DESCRIPTION \u2502', '\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524', diff --git a/test/integration/projects-get.test.ts b/test/integration/projects-get.test.ts index a791287b..2316d229 100644 --- a/test/integration/projects-get.test.ts +++ b/test/integration/projects-get.test.ts @@ -2,7 +2,7 @@ import nock from 'nock'; import { buildApi } from '../../src/resources'; import type { Project } from '../../src/projects/types'; -import { PROJECT_DESCRIPTION_COLUMN, PROJECT_DETAIL_COLUMNS } from '../../src/projects/project.presenter'; +import { PROJECT_DETAIL_COLUMNS } from '../../src/projects/project.presenter'; import { LaunchApiError } from '../../src/transport/errors'; import { RestApiClient } from '../../src/transport/rest-client'; import { renderTable } from '../../src/core/render'; @@ -117,7 +117,7 @@ describe('integration: GET /projects/{project_uid}', () => { const { ux, lines } = recordingUx(); const project = await buildApi(buildClient(), UNUSED_CMA, {} as never, {} as never).projects.get({ org: ORG_UID, project: PROJECT_UID }); - renderTable(ux, PROJECT_DETAIL_COLUMNS, [project], undefined, PROJECT_DESCRIPTION_COLUMN); + renderTable(ux, PROJECT_DETAIL_COLUMNS, [project], undefined); expect(lines).toEqual([ '\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510', @@ -147,7 +147,7 @@ describe('integration: GET /projects/{project_uid}', () => { const { ux, lines } = recordingUx(); const project = await buildApi(buildClient(), UNUSED_CMA, {} as never, {} as never).projects.get({ org: ORG_UID, project: FILEUPLOAD_PROJECT_UID }); - renderTable(ux, PROJECT_DETAIL_COLUMNS, [project], undefined, PROJECT_DESCRIPTION_COLUMN); + renderTable(ux, PROJECT_DETAIL_COLUMNS, [project], undefined); expect(lines).toEqual([ '\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510', diff --git a/test/integration/projects-list-command.test.ts b/test/integration/projects-list-command.test.ts index 90570981..1c5cd44a 100644 --- a/test/integration/projects-list-command.test.ts +++ b/test/integration/projects-list-command.test.ts @@ -176,6 +176,25 @@ describe('integration: shipped commands driven through oclif runCommand', () => expect(scope.isDone()).toBe(false); }); + it('words a non-numeric --limit as one sentence on stderr, with no oclif "Parsing" text, and exits 2 before any request', async () => { + const scope = nock(LAUNCH_HUB_URL).get('/manage/projects').query(true).reply(200, listFixture); + + const { error, stdout, stderr } = await runLaunch([ + 'launch:projects:list', + '--org', + ORG_UID, + '--limit', + 'abc', + '--data-dir', + DATA_DIR, + ]); + + expect(error?.oclif?.exit).toBe(2); + expect(stdout).toBe(''); + expect(stderr).toBe('error: Invalid --limit value "abc". Provide a whole number from 1 to 1000.\n'); + expect(scope.isDone()).toBe(false); + }); + it('sends --limit 1, the smallest page it accepts', async () => { const scope = nock(LAUNCH_HUB_URL).get('/manage/projects').query({ limit: '1', skip: '0' }).reply(200, listFixture);