UNPKG

@swell/cli

Version:

Swell's command line interface/utility

83 lines (78 loc) 3.23 kB
import { InspectResourceCommand, inspectResourceBaseArgs, inspectResourceBaseFlags, } from '../../inspect-resource-command.js'; import { isObjectId } from '../../lib/apps/object-id.js'; import { resolveAppId } from '../../lib/apps/resolve.js'; import { formatSettingsKey, groupSettingsRecord, isDeprecatedRecord, parseSettingsKey, } from '../../lib/inspect/settings.js'; export default class Settings extends InspectResourceCommand { static summary = 'App and platform settings records.'; static description = `Lists app settings records plus platform 'com.*' system records, grouped by owner. Pass --app=<slug> or --app=. (current swell.json) to scope. Each app collapses to one settings record at push time, so the list shows one row per app. Pass an identifier to view a single record as JSON. Identifier forms: <name> — system record (e.g. taxes, payments) app.<slug> — app record com.<name> — full system id <24-char id> — direct fetch Deprecated records (general, admin) are filtered from the list but remain reachable by name. `; static args = { ...inspectResourceBaseArgs }; static flags = { ...inspectResourceBaseFlags }; static examples = [ 'swell inspect settings', 'swell inspect settings --app=my-app', 'swell inspect settings taxes', 'swell inspect settings app.notify_me', 'swell inspect settings com.payments', 'swell inspect settings --live', 'swell inspect settings taxes --json', ]; resourceLabel = 'Settings'; resourceLabelSingular = 'settings record'; adminPath = '/data/:settings'; commandName = 'settings'; async run() { const { args, flags } = await this.parse(Settings); await this.runInspect({ args, flags }); } keyFor(record, appSlugById) { return formatSettingsKey(record, appSlugById); } groupForRecord(record, appSlugById) { return groupSettingsRecord(record, appSlugById); } filterListResults(results) { return results.filter((r) => !isDeprecatedRecord(r)); } hints(record) { if (!record.name) { return []; } return [`swell api get '/settings/${record.name}'`]; } async showDetail(identifier, _scope, flags) { const parsed = parseSettingsKey(identifier); let segment; switch (parsed.kind) { case 'app': { segment = isObjectId(parsed.ref) ? parsed.ref : await resolveAppId(this.api, parsed.ref); break; } case 'path': { segment = parsed.segment; break; } case 'invalid': { this.error(`Invalid ${this.resourceLabelSingular} identifier '${identifier}'. ` + `Expected bare name (e.g. taxes), app.<slug>, full id (e.g. com.taxes), or 24-char id.`, { exit: 1 }); } } const record = await this.api.get({ adminPath: `${this.adminPath}/${segment}`, }); if (!record) { this.throwNotFound(identifier); } this.emitDetail(record, flags); } }