diff --git a/README-template.md b/README-template.md new file mode 100644 index 0000000..570e0b7 --- /dev/null +++ b/README-template.md @@ -0,0 +1,63 @@ +# Octomind CLI + +![Continuous Integration](https://github.com/octomind-dev/cli/actions/workflows/ts.yml/badge.svg) + +A command-line interface for interacting with the Octomind API. +This CLI allows you to execute tests, retrieve test reports, and manage private locations as well as environments. +See [API documentation](https://octomind.dev/docs/api-reference/) + +## Usage + +1. Install the package - `npm i -g @octomind/octomind` and use it directly e.g. `octomind -h` +2. Use the cli through npx e.g. `npx @octomind/octomind -h` + + +${commands} + +## Output Formats + +By default, the CLI provides formatted text output for better readability. Add the `--json` flag to any command to get the raw JSON response instead. This is useful for scripting or when you need to process the output programmatically. + +Example of JSON output: +```json +{ + "id": "826c15af-644b-4b28-89b4-f50ff34e46b7", + "testTargetId": "3435918b-3d29-4ebd-8c68-9a540532f45a", + "status": "PASSED", + "executionUrl": "https://example.com", + "testResults": [ + { + "id": "abc-123-456", + "testTargetId": "3435918b-3d29-4ebd-8c68-9a540532f45a", + "testCaseId": "test-1", + "status": "PASSED", + "traceUrl": "https://storage.googleapis.com/automagically-traces/abc-123-trace.zip" + }, + { + "id": "def-456-789", + "testTargetId": "3435918b-3d29-4ebd-8c68-9a540532f45a", + "testCaseId": "test-2", + "status": "PASSED", + "traceUrl": "https://storage.googleapis.com/automagically-traces/def-456-trace.zip" + } + ] +} +``` + +## Development + +1. Clone the repository +2. Install dependencies: +```bash +pnpm install +``` + +The CLI is written in TypeScript and uses the following dependencies: +- [commander](https://github.com/tj/commander.js): For command-line argument parsing +- [openapi-fetch](https://openapi-ts.dev/openapi-fetch/): For making openapi API calls +- [openapi-typescript](https://openapi-ts.dev/introduction): For generating types from openapi spec + +To build from source: +```bash +pnpm run build +``` \ No newline at end of file diff --git a/README.md b/README.md index 0aced45..e2b95ff 100644 --- a/README.md +++ b/README.md @@ -11,275 +11,283 @@ See [API documentation](https://octomind.dev/docs/api-reference/) 1. Install the package - `npm i -g @octomind/octomind` and use it directly e.g. `octomind -h` 2. Use the cli through npx e.g. `npx @octomind/octomind -h` + +# octomind + +Octomind cli tool. Version: 1.0.5. Additional documentation see https://octomind.dev/docs/api-reference/ + +**Usage:** `octomind [options] [command]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-V, --version` | output the version number | No | | + +# octomind CLI Documentation + +Octomind cli tool. Version: 1.0.5. Additional documentation see https://octomind.dev/docs/api-reference/ + ## Commands -### Init +## init -Initialize configuration by setting up your API key and optionally a test target ID. This allows you to avoid passing these parameters for subsequent commands. +Initialize configuration by setting up API key -```bash -octomind init \ - [--api-key ] \ - [--test-target-id ] \ - [--force] -``` +**Usage:** `init [options]` -Options: -- `-k, --api-key`: Your Octomind API key (will prompt if not provided) -- `-t, --test-target-id`: Test target ID (optional) -- `-f, --force`: Force overwrite existing configuration +### Options -If you don't provide the API key via the command line option, the CLI will prompt you to enter it interactively. You can get your API key from https://octomind.dev/docs/run-tests/execution-curl#create-an-api-key. +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-t, --test-target-id ` | Test target ID | Yes | | +| `-k, --api-key ` | the api key for authentication | Yes | | +| `-f, --force` | Force overwrite existing configuration | No | | -### Execute Tests +## debug -Run test cases against a specified URL. +run test cases against local build -```bash -octomind execute \ - --url \ - [--api-key ] \ - [--test-target-id ] \ - [--environment ] \ - [--tags ] \ - [-v, --variables-to-overwrite ] \ - [--description ] \ - [--json] -``` +**Usage:** `debug [options]` -Options: -- `-u, --url` (required): URL to test -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-t, --test-target-id`: Test target ID (optional if configured via `init`) -- `-e, --environment`: Environment name (default: "default") -- `-d, --description`: Test description -- `-g, --tags`: comma separated list of tags for tests to execute -- `-v, --variables-to-overwrite`: JSON object for variables to override for this run e.g. `{ "key": ["v1", "v2"]}` -- `-j, --json`: Output raw JSON response +### Options -### Get Test Report +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-u, --url ` | url the tests should run against | Yes | | +| `-i, --id [uuid]` | id of the test case you want to run, if not provided will run all test cases in the test target | No | | +| `-e, --environment-id [uuid]` | id of the environment you want to run against, if not provided will run all test cases against the default environment | No | | +| `-a, --test-target-id [uuid]` | id of the test target of the test case, if not provided will use the test target id from the config | No | | +| `--headless` | if we should run headless without the UI of playwright and the browser | No | | +| `--persist` | if we should write playwright config and files to current directory, you can then run 'npx playwright test' to run them again | No | | +| `--grep [substring]` | filter test cases by substring | No | | -Retrieve details about a specific test report. +## execute -```bash -octomind report \ - --report-id \ - [--api-key ] \ - [--test-target-id ] \ - [--json] -``` +Execute test cases -Options: -- `-r, --report-id` (required): Test report ID -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-t, --test-target-id`: Test target ID (optional if configured via `init`) -- `-j, --json`: Output raw JSON response +**Usage:** `execute [options]` -Example text output: -``` -Test Report Details: -Status: PASSED -Execution URL: https://example.com - -Test Results: -- Test abc-123-456: PASSED - Trace: https://storage.googleapis.com/automagically-traces/abc-123-trace.zip -- Test def-456-789: PASSED - Trace: https://storage.googleapis.com/automagically-traces/def-456-trace.zip -``` +### Options -Example JSON output: -```json -{ - "id": "826c15af-644b-4b28-89b4-f50ff34e46b7", - "testTargetId": "3435918b-3d29-4ebd-8c68-9a540532f45a", - "status": "PASSED", - "executionUrl": "https://example.com", - "testResults": [ - { - "id": "abc-123-456", - "testTargetId": "3435918b-3d29-4ebd-8c68-9a540532f45a", - "testCaseId": "test-1", - "status": "PASSED", - "traceUrl": "https://storage.googleapis.com/automagically-traces/abc-123-trace.zip" - }, - { - "id": "def-456-789", - "testTargetId": "3435918b-3d29-4ebd-8c68-9a540532f45a", - "testCaseId": "test-2", - "status": "PASSED", - "traceUrl": "https://storage.googleapis.com/automagically-traces/def-456-trace.zip" - } - ] -} -``` +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-u, --url ` | URL to test | Yes | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | +| `-e, --environment-name [name]` | Environment name | No | default | +| `-d, --description [text]` | Test description | No | | +| `-g, --tags [tags]` | comma separated list of tags | No | | +| `-v, --variables-to-overwrite [variables]` | JSON object of variables to overwrite | No | | -### Register Private Location +## test-report -Register a new private location worker. If you use the [private location worker](https://github.com/OctoMind-dev/private-location-worker) it will register itself on startup automatically. +Get test report details -```bash -octomind register-location \ - --name \ - --proxypass \ - --proxyuser \ - --address
\ - [--api-key ] \ - [--json] -``` +**Usage:** `test-report [options]` -Options: -- `-n, --name` (required): Location name -- `-p, --proxypass` (required): Proxy password -- `-u, --proxyuser` (required): Proxy user -- `-a, --address` (required): Location address (format: IP:PORT) -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-j, --json`: Output raw JSON response +### Options -### Unregister Private Location +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-r, --test-report-id ` | Test report ID | Yes | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | -Remove a registered private location worker. If you use the [private location worker](https://github.com/OctoMind-dev/private-location-worker) it will unregister itself when going offline automatically. +## register-location -```bash -octomind unregister-location \ - --name \ - [--api-key ] \ - [--json] -``` +Register a private location -Options: -- `-n, --name` (required): Location name -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-j, --json`: Output raw JSON response +**Usage:** `register-location [options]` -### List Private Locations +### Options -List all registered private locations. +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-n, --name ` | Location name | Yes | | +| `-p, --password ` | Proxy password | Yes | | +| `-u, --username ` | Proxy user | Yes | | +| `-a, --address
` | Location address | Yes | | -```bash -octomind list-private-locations \ - [--api-key ] \ - [--json] -``` +## unregister-location -Options: -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-j, --json`: Output raw JSON response +Unregister a private location -Example text output: -``` -Private Locations: -- Name: location-1 - Status: ONLINE - Address: https://location-1.example.com -- Name: location-2 - Status: OFFLINE - Address: https://location-2.example.com -``` +**Usage:** `unregister-location [options]` -### List Environments +### Options -List all available environments. +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-n, --name ` | Location name | Yes | | -```bash -octomind list-environments \ - [--api-key ] \ - [--test-target-id ] \ - [--json] -``` +## list-private-locations -Options: -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-t, --test-target-id`: Test target ID (optional if configured via `init`) -- `-j, --json`: Output raw JSON response +List all private locations -### Create Environment +**Usage:** `list-private-locations [options]` -Create a new environment for a test target. +### Options -```bash -octomind create-environment \ - --name \ - --discovery-url \ - [--api-key ] \ - [--test-target-id ] \ - [--test-account-username ] \ - [--test-account-password ] \ - [--test-account-otp-initializer-key ] \ - [--basic-auth-username ] \ - [--basic-auth-password ] \ - [--private-location-name ] \ - [--additional-header-fields ] \ - [--json] -``` +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | -Options: -- `-n, --name` (required): Environment name -- `-d, --discovery-url` (required): Discovery URL -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-t, --test-target-id`: Test target ID (optional if configured via `init`) -- `--test-account-username`: Test account username -- `--test-account-password`: Test account password -- `--test-account-otp-initializer-key`: OTP initializer key for test account -- `--basic-auth-username`: Basic auth username -- `--basic-auth-password`: Basic auth password -- `--private-location-name`: Private location name -- `--additional-header-fields`: Additional header fields (JSON string) -- `-j, --json`: Output raw JSON response +## list-environments -### Update Environment +List all environments -Update an existing environment. +**Usage:** `list-environments [options]` -```bash -octomind update-environment \ - --environment-id \ - [--api-key ] \ - [--test-target-id ] \ - [--name ] \ - [--discovery-url ] \ - [--test-account-username ] \ - [--test-account-password ] \ - [--test-account-otp-initializer-key ] \ - [--basic-auth-username ] \ - [--basic-auth-password ] \ - [--private-location-name ] \ - [--additional-header-fields ] \ - [--json] -``` +### Options -Options: -- `-e, --environment-id` (required): Environment ID -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-t, --test-target-id`: Test target ID (optional if configured via `init`) -- `-n, --name`: New environment name -- `-d, --discovery-url`: New discovery URL -- `--test-account-username`: New test account username -- `--test-account-password`: New test account password -- `--test-account-otp-initializer-key`: New OTP initializer key for test account -- `--basic-auth-username`: New basic auth username -- `--basic-auth-password`: New basic auth password -- `--private-location-name`: New private location name -- `--additional-header-fields`: New additional header fields (JSON string) -- `-j, --json`: Output raw JSON response - -### Delete Environment - -Delete an existing environment. +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | + +## create-environment + +Create a new environment + +**Usage:** `create-environment [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-n, --name ` | Environment name | Yes | | +| `-d, --discovery-url ` | Discovery URL | Yes | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | +| `--test-account-username [username]` | Test account username | No | | +| `--test-account-password [password]` | Test account password | No | | +| `--test-account-otp-initializer-key [key]` | Test account OTP initializer key | No | | +| `--basic-auth-username [username]` | Basic auth username | No | | +| `--basic-auth-password [password]` | Basic auth password | No | | +| `--private-location-name [name]` | Private location name | No | | + +## update-environment + +Update an existing environment + +**Usage:** `update-environment [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-e, --environment-id ` | Environment ID | Yes | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | +| `-n, --name [name]` | Environment name | No | | +| `-d, --discovery-url [url]` | Discovery URL | No | | +| `--test-account-username [username]` | Test account username | No | | +| `--test-account-password [password]` | Test account password | No | | +| `--test-account-otp-initializer-key [key]` | Test account OTP initializer key | No | | +| `--basic-auth-username [username]` | Basic auth username | No | | +| `--basic-auth-password [password]` | Basic auth password | No | | +| `--private-location-name [name]` | Private location name | No | | + +## delete-environment + +Delete an environment + +**Usage:** `delete-environment [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-e, --environment-id ` | Environment ID | Yes | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | + +## start-private-location + +Start a private location worker, see https://octomind.dev/docs/proxy/private-location + +**Usage:** `start-private-location [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-n, --name [name]` | Location name | No | | +| `-u, --username [username]` | Proxy user | No | | +| `-p, --password [password]` | Proxy password | No | | +| `-l, --host-network` | Use host network (default: false). If set you can use localhost directly | No | false | + +## stop-private-location + +Stop a private location worker, see https://octomind.dev/docs/proxy/private-location + +**Usage:** `stop-private-location [options]` + +## notifications + +Get notifications for a test target + +**Usage:** `notifications [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | + +## test-case + +Get details of a specific test case + +**Usage:** `test-case [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-c, --test-case-id ` | Test case ID | Yes | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | + +## create-discovery + +Create a new test case discovery + +**Usage:** `create-discovery [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-n, --name ` | Discovery name | Yes | | +| `-p, --prompt ` | Discovery prompt | Yes | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | +| `-e, --entry-point-url-path [path]` | Entry point URL path | No | | +| `--prerequisite-id [id]` | Prerequisite test case ID | No | | +| `--external-id [id]` | External identifier | No | | +| `--assigned-tag-ids [ids]` | Comma-separated list of tag IDs | No | | +| `--folder-id [id]` | Folder ID | No | | + +## list-test-cases + +List all test cases + +**Usage:** `list-test-cases [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | +| `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | -```bash -octomind delete-environment \ - --environment-id \ - [--api-key ] \ - [--test-target-id ] \ - [--json] -``` -Options: -- `-e, --environment-id` (required): Environment ID -- `-k, --api-key`: Your Octomind API key (optional if configured via `init`) -- `-t, --test-target-id`: Test target ID (optional if configured via `init`) -- `-j, --json`: Output raw JSON response ## Output Formats @@ -320,9 +328,11 @@ pnpm install ``` The CLI is written in TypeScript and uses the following dependencies: -- `commander`: For command-line argument parsing +- [commander](https://github.com/tj/commander.js): For command-line argument parsing +- [openapi-fetch](https://openapi-ts.dev/openapi-fetch/): For making openapi API calls +- [openapi-typescript](https://openapi-ts.dev/introduction): For generating types from openapi spec To build from source: ```bash pnpm run build -``` \ No newline at end of file +``` diff --git a/package.json b/package.json index f094c1b..3b7a3f3 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,10 @@ "octomind": "./dist/index.js" }, "scripts": { + "gendoc": "tsx scripts/generate-docs.ts > README.md", "lint": "pnpm apigen &&npx genversion -des src/version.ts && eslint src/**/*.ts tests/**/*.ts --max-warnings=0", "apigen": "openapi-typescript ./openapi.yaml --output src/api.ts", - "build": "pnpm apigen && npx genversion -des src/version.ts && tsc --project tsconfig.build.json", + "build": "pnpm apigen && npx genversion -des src/version.ts && pnpm gendoc && tsc --project tsconfig.build.json", "octomind": "pnpm apigen && tsx src/index.ts", "test": "pnpm apigen && npx genversion -des src/version.ts && jest", "test:watch": "pnpm apigen && npx genversion -e src/version.ts && jest --watch" diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts new file mode 100755 index 0000000..1591554 --- /dev/null +++ b/scripts/generate-docs.ts @@ -0,0 +1,97 @@ +#!/usr/bin/env ts-node +import { Command } from 'commander'; +import { buildCmd } from '../src/cli'; +import * as fs from 'fs'; +import * as path from 'path'; + +/** + * Generate markdown documentation for all commands in the CLI + */ +function generateCommandDocs(command: Command, level = 1): string { + let docs = ''; + + // Skip the root command if it's the first level + if (level > 1 || command.name() !== 'octomind-cli') { + const prefix = '#'.repeat(level); + docs += `${prefix} ${command.name()}\n\n`; + + if (command.description()) { + docs += `${command.description()}\n\n`; + } + + // Add usage information + const usage = command.usage(); + if (usage) { + docs += `**Usage:** \`${command.name()} ${usage}\`\n\n`; + } + + // Add options + const options = command.options; + if (options && options.length > 0) { + docs += '### Options\n\n'; + docs += '| Option | Description | Required | Default |\n'; + docs += '|--------|-------------|----------|--------|\n'; + + options.forEach(option => { + const flags = option.flags; + const description = option.description || ''; + const defaultValue = option.defaultValue !== undefined ? String(option.defaultValue) : ''; + const requiredText = option.required ? 'Yes' : 'No'; + + docs += `| \`${flags}\` | ${description} | ${requiredText} | ${defaultValue} |\n`; + }); + + docs += '\n'; + } + } + + // Process subcommands + const subcommands = command.commands; + if (subcommands && subcommands.length > 0) { + // If this is the root command, add a title + if (level === 1) { + docs += `# ${command.name()} CLI Documentation\n\n`; + docs += `${command.description()}\n\n`; + docs += '## Commands\n\n'; + } + + subcommands.forEach(subcommand => { + docs += generateCommandDocs(subcommand, level + 1); + }); + } + + return docs; +} + +/** + * Main function to generate documentation + */ +async function main() { + try { + // Get the program object from buildCmd + const program = buildCmd(); + + // Generate markdown documentation + const markdown = generateCommandDocs(program); + + // Check if README template exists + const templatePath = path.join(__dirname, '..', 'README-template.md'); + if (fs.existsSync(templatePath)) { + // Load template and replace ${commands} with generated docs + const template = fs.readFileSync(templatePath, 'utf8'); + const result = template.replace('${commands}', markdown); + + // Output the result to console (can be redirected to a file) + console.log(result); + } else { + // If template doesn't exist, just output the docs + console.log(markdown); + } + } catch (error) { + console.error('Error generating documentation:', error); + process.exit(1); + } +} + +// Run the main function +main().catch(console.error); diff --git a/src/cli.ts b/src/cli.ts index 52de606..716a9ed 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,4 +1,4 @@ -import { program, Command } from "commander"; +import { program, Command, Option } from "commander"; import { version } from "./version"; import { createDiscovery, @@ -30,11 +30,14 @@ const createCommandWithCommonOptions = (command: string): Command => { const splitter = (value: string): string[] => value.split(/,| |\|/); const toJSON = (value: string): object => JSON.parse(value); +const testTargetIdOption = new Option("-t, --test-target-id [id]", + "Test target ID, if not provided will use the test target id from the config"); + export const buildCmd = (): Command => { program - .name("octomind-cli") + .name("octomind") .description( - `Octomind CLI tool. Version: ${version}. see https://octomind.dev/docs/api-reference/` + `Octomind cli tool. Version: ${version}. Additional documentation see https://octomind.dev/docs/api-reference/`, ) .version(version); @@ -110,16 +113,16 @@ export const buildCmd = (): Command => { .description("run test cases against local build") .requiredOption("-u, --url ", "url the tests should run against") .option( - "-i, --id ", - "id of the test case you want to run, if not provided will run all test cases in the test target" + "-i, --id [uuid]", + "id of the test case you want to run, if not provided will run all test cases in the test target", ) .option( - "-e, --environmentId ", - "id of the environment you want to run against, if not provided will run all test cases against the default environment" + "-e, --environment-id [uuid]", + "id of the environment you want to run against, if not provided will run all test cases against the default environment", ) .option( - "-a, --testTargetId ", - "id of the test target of the test case" + "-a, --test-target-id [uuid]", + "id of the test target of the test case, if not provided will use the test target id from the config", ) .option( "--headless", @@ -129,7 +132,7 @@ export const buildCmd = (): Command => { "--persist", "if we should write playwright config and files to current directory, you can then run 'npx playwright test' to run them again" ) - .option("--grep ", "filter test cases by substring") + .option("--grep [substring]", "filter test cases by substring") .action(async (options, command) => { const resolvedTestTargetId = await resolveTestTargetId( options.testTargetId @@ -141,12 +144,12 @@ export const buildCmd = (): Command => { createCommandWithCommonOptions("execute") .description("Execute test cases") .requiredOption("-u, --url ", "URL to test") - .option("-t, --test-target-id ", "Test target ID") - .option("-e, --environmentName ", "Environment name", "default") - .option("-d, --description ", "Test description") - .option("-g, --tags ", "comma separated list of tags", splitter) + .addOption(testTargetIdOption) + .option("-e, --environment-name [name]", "Environment name", "default") + .option("-d, --description [text]", "Test description") + .option("-g, --tags [tags]", "comma separated list of tags", splitter) .option( - "-v, --variables-to-overwrite ", + "-v, --variables-to-overwrite [variables]", "JSON object of variables to overwrite", toJSON ) @@ -161,7 +164,7 @@ export const buildCmd = (): Command => { createCommandWithCommonOptions("test-report") .description("Get test report details") .requiredOption("-r, --test-report-id ", "Test report ID") - .option("-t, --test-target-id ", "Test target ID") + .addOption(testTargetIdOption) .action(async (options) => { const testTargetId = await resolveTestTargetId(options.testTargetId); await listTestReport({ @@ -189,7 +192,7 @@ export const buildCmd = (): Command => { createCommandWithCommonOptions("list-environments") .description("List all environments") - .option("-t, --test-target-id ", "Test target ID") + .addOption(testTargetIdOption) .action(async (options, command) => { const resolvedTestTargetId = await resolveTestTargetId( options.testTargetId @@ -202,16 +205,16 @@ export const buildCmd = (): Command => { .description("Create a new environment") .requiredOption("-n, --name ", "Environment name") .requiredOption("-d, --discovery-url ", "Discovery URL") - .option("-t, --test-target-id ", "Test target ID") - .option("--test-account-username ", "Test account username") - .option("--test-account-password ", "Test account password") + .addOption(testTargetIdOption) + .option("--test-account-username [username]", "Test account username") + .option("--test-account-password [password]", "Test account password") .option( - "--test-account-otp-initializer-key ", - "Test account OTP initializer key" + "--test-account-otp-initializer-key [key]", + "Test account OTP initializer key", ) - .option("--basic-auth-username ", "Basic auth username") - .option("--basic-auth-password ", "Basic auth password") - .option("--private-location-name ", "Private location name") + .option("--basic-auth-username [username]", "Basic auth username") + .option("--basic-auth-password [password]", "Basic auth password") + .option("--private-location-name [name]", "Private location name") .action(async (_, options) => createEnvironment({ ...options, @@ -222,18 +225,18 @@ export const buildCmd = (): Command => { createCommandWithCommonOptions("update-environment") .description("Update an existing environment") .requiredOption("-e, --environment-id ", "Environment ID") - .option("-t, --test-target-id ", "Test target ID") - .option("-n, --name ", "Environment name") - .option("-d, --discovery-url ", "Discovery URL") - .option("--test-account-username ", "Test account username") - .option("--test-account-password ", "Test account password") + .addOption(testTargetIdOption) + .option("-n, --name [name]", "Environment name") + .option("-d, --discovery-url [url]", "Discovery URL") + .option("--test-account-username [username]", "Test account username") + .option("--test-account-password [password]", "Test account password") .option( - "--test-account-otp-initializer-key ", - "Test account OTP initializer key" + "--test-account-otp-initializer-key [key]", + "Test account OTP initializer key", ) - .option("--basic-auth-username ", "Basic auth username") - .option("--basic-auth-password ", "Basic auth password") - .option("--private-location-name ", "Private location name") + .option("--basic-auth-username [username]", "Basic auth username") + .option("--basic-auth-password [password]", "Basic auth password") + .option("--private-location-name [name]", "Private location name") .action(async (_, options) => updateEnvironment({ ...options, @@ -244,15 +247,15 @@ export const buildCmd = (): Command => { createCommandWithCommonOptions("delete-environment") .description("Delete an environment") .requiredOption("-e, --environment-id ", "Environment ID") - .option("-t, --test-target-id ", "Test target ID") + .addOption(testTargetIdOption) .action(deleteEnvironment); program .command("start-private-location") - .description("Start a private location worker") - .option("-n, --name ", "Location name") - .option("-u, --username ", "Proxy user") - .option("-p, --password ", "Proxy password") + .description("Start a private location worker, see https://octomind.dev/docs/proxy/private-location") + .option("-n, --name [name]", "Location name") + .option("-u, --username [username]", "Proxy user") + .option("-p, --password [password]", "Proxy password") .option( "-l, --host-network", "Use host network (default: false). If set you can use localhost directly", @@ -262,12 +265,12 @@ export const buildCmd = (): Command => { program .command("stop-private-location") - .description("Stop a private location worker") + .description("Stop a private location worker, see https://octomind.dev/docs/proxy/private-location") .action(stopPLW); createCommandWithCommonOptions("notifications") .description("Get notifications for a test target") - .option("-t, --test-target-id ", "Test target ID") + .addOption(testTargetIdOption) .action(async (options, command) => { const resolvedTestTargetId = await resolveTestTargetId( options.testTargetId @@ -279,7 +282,7 @@ export const buildCmd = (): Command => { createCommandWithCommonOptions("test-case") .description("Get details of a specific test case") .requiredOption("-c, --test-case-id ", "Test case ID") - .option("-t, --test-target-id ", "Test target ID") + .addOption(testTargetIdOption) .action(async (options, command) => { const resolvedTestTargetId = await resolveTestTargetId( options.testTargetId @@ -292,16 +295,14 @@ export const buildCmd = (): Command => { .description("Create a new test case discovery") .requiredOption("-n, --name ", "Discovery name") .requiredOption("-p, --prompt ", "Discovery prompt") - .option("-t, --test-target-id ", "Test target ID") - .option("-e, --entry-point-url-path ", "Entry point URL path") - .option("--prerequisite-id ", "Prerequisite test case ID") - .option("--external-id ", "External identifier") + .addOption(testTargetIdOption) + .option("-e, --entry-point-url-path [path]", "Entry point URL path") + .option("--prerequisite-id [id]", "Prerequisite test case ID") + .option("--external-id [id]", "External identifier") .option( - "--assigned-tag-ids ", - "Comma-separated list of tag IDs", - splitter + "--assigned-tag-ids [ids]", "Comma-separated list of tag IDs", splitter, ) - .option("--folder-id ", "Folder ID") + .option("--folder-id [id]", "Folder ID") .action(async (options, command) => { const resolvedTestTargetId = await resolveTestTargetId( options.testTargetId @@ -312,7 +313,7 @@ export const buildCmd = (): Command => { createCommandWithCommonOptions("list-test-cases") .description("List all test cases") - .option("-t, --test-target-id ", "Test target ID") + .addOption(testTargetIdOption) .action(async (options, command) => { const resolvedTestTargetId = await resolveTestTargetId( options.testTargetId, diff --git a/tests/cli.spec.ts b/tests/cli.spec.ts index 76062c3..ada8648 100644 --- a/tests/cli.spec.ts +++ b/tests/cli.spec.ts @@ -97,7 +97,7 @@ describe("config overwrite behaviour", () => { "debug", "--url", "https://example.com", - "--testTargetId", + "--test-target-id", providedTestTargetId, ]);