qqq <noun> <verb> for table (list, describe, query, count, get, create, update, delete, export), process (list, describe, run) and job (list, get, logs, cancel, retry), with the 0.1 flat commands kept as hidden aliases. Global --output json|table|text|csv|yaml, --json, --query (JMESPath), --fields, --yes and --trace work before or after the subcommand. Filters take --where, --group (AND/OR with parentheses), --or, --order, --filter-json, --print-filter and --count; queries page with --limit, --skip and --all. qqq api <operationId> calls any operation from the generated index (--path, --param, --body-json, --form, --bytes, --out). Exit codes: 2 usage and bad filters, 3 auth, 4 unreachable or rate limited, 5 not found, 6 validation, 70 server error. The realtime stream can carry a session cookie for tail. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
82 lines
3.8 KiB
JavaScript
82 lines
3.8 KiB
JavaScript
#!/usr/bin/env node
|
|
/*
|
|
* Copyright 2026 QRun.IO, Inc.
|
|
* Licensed under the Apache License, Version 2.0 (see LICENSE).
|
|
*/
|
|
|
|
/**
|
|
* qqq - the command-line client for QQQ applications. Every call is an operation of the QQQ UI API
|
|
* (/qqq/v1); nothing is hard-coded about an application: apps, tables, fields and processes all
|
|
* come from metadata. Grammar: `qqq <noun> <verb>` (table, process, job, api), plus the flat
|
|
* commands of 0.1 (apps, tables, query, get, run, jobs, tail) as aliases.
|
|
*/
|
|
|
|
import { Command, CommanderError } from 'commander'
|
|
import { UI_API_VERSION } from '@qrun-io/qqq-ui-api-client'
|
|
import { Context, EXIT, describeError } from './context.js'
|
|
import { CLI_VERSION } from './session.js'
|
|
import { registerApi } from './commands/api.js'
|
|
import { registerAuth } from './commands/auth.js'
|
|
import { registerJob } from './commands/job.js'
|
|
import { registerMisc } from './commands/misc.js'
|
|
import { registerProcess } from './commands/process.js'
|
|
import { registerTable } from './commands/table.js'
|
|
|
|
const program = new Command()
|
|
program
|
|
.name('qqq')
|
|
.description('Command-line client for QQQ applications, built only on the QQQ UI API (/qqq/v1).')
|
|
.version(`${CLI_VERSION} (UI API client ${UI_API_VERSION})`)
|
|
.option('-s, --server <url>', 'the QQQ server (default: QQQ_SERVER, or the last one signed in to)')
|
|
.option('-O, --output <format>', 'json, table, text, csv or yaml (default: table on a terminal, json in a pipe; QQQ_OUTPUT)')
|
|
.option('--json', 'same as --output json')
|
|
.option('-Q, --query <jmespath>', 'reshape the output with a JMESPath expression, as `aws --query`')
|
|
.option('--fields <names>', 'comma-separated columns to show in table, text and csv output')
|
|
.option('-y, --yes', 'answer yes to confirmations (delete, cancel)')
|
|
.option('--trace', 'print stack traces for unexpected errors')
|
|
.exitOverride()
|
|
.configureOutput({ writeErr: (text) => process.stderr.write(text) })
|
|
|
|
let context: Context | undefined
|
|
const ctx = () => (context ??= new Context(program))
|
|
|
|
registerAuth(program, ctx)
|
|
registerMisc(program, ctx)
|
|
registerTable(program, ctx)
|
|
registerProcess(program, ctx)
|
|
registerJob(program, ctx)
|
|
registerApi(program, ctx)
|
|
|
|
/** Flat aliases from 0.1: forward to the noun-verb commands with the same options. */
|
|
function alias(flat: string, noun: string, verb: string, description: string): void {
|
|
const target = program.commands.find((c) => c.name() === noun)!.commands.find((c) => c.name() === verb)!
|
|
const cmd = program.command(`${flat} ${target.registeredArguments.map((a) => (a.required ? `<${a.name()}>` : `[${a.name()}]`)).join(' ')}`.trim(), { hidden: true }).description(`${description} (alias of \`qqq ${noun} ${verb}\`)`)
|
|
for (const option of target.options) cmd.addOption(option)
|
|
cmd.action(async (...args: unknown[]) => {
|
|
const commandArgs = args.slice(0, -2) as string[]
|
|
const options = args[args.length - 2] as Record<string, unknown>
|
|
const argv: string[] = [...commandArgs]
|
|
for (const option of target.options) {
|
|
const value = options[option.attributeName()]
|
|
if (value === undefined || value === false) continue
|
|
if (value === true) argv.push(option.long!)
|
|
else if (Array.isArray(value)) for (const v of value) argv.push(option.long!, String(v))
|
|
else argv.push(option.long!, String(value))
|
|
}
|
|
await target.parseAsync(argv, { from: 'user' })
|
|
})
|
|
}
|
|
alias('query', 'table', 'query', 'Query a table')
|
|
alias('get', 'table', 'get', 'View one record')
|
|
alias('run', 'process', 'run', 'Run a process')
|
|
|
|
program.parseAsync().catch((error: unknown) => {
|
|
if (error instanceof CommanderError) {
|
|
process.exitCode = error.exitCode === 0 ? 0 : EXIT.usage
|
|
return
|
|
}
|
|
const { code, text } = describeError(error, Boolean(program.opts().trace))
|
|
process.stderr.write(text + '\n')
|
|
process.exitCode = code
|
|
})
|