@swell/cli
Version:
Swell's command line interface/utility
50 lines (47 loc) • 2.18 kB
JavaScript
import { InspectResourceCommand, inspectResourceBaseArgs, inspectResourceBaseFlags, } from '../../inspect-resource-command.js';
import { resolveAppId } from '../../lib/apps/resolve.js';
import { groupContentRecord, resolveContentKey, reverseResolveContentId, } from '../../lib/inspect/content.js';
export default class Content extends InspectResourceCommand {
static summary = 'App and platform content views.';
static description = `Lists content view extensions across all apps plus platform 'custom' sources, grouped by owner. Pass --app=<slug> or --app=. (current swell.json) to scope.
Pass an identifier to view a single record as JSON.
Identifier forms:
app.<app>.<name> — app-owned view (list column 1)
custom.<source>.<name> — platform custom view (e.g. custom.admin.products)
<name> — requires --app= scope
`;
static args = { ...inspectResourceBaseArgs };
static flags = { ...inspectResourceBaseFlags };
static examples = [
'swell inspect content',
'swell inspect content --app=my-app',
'swell inspect content app.honest_reviews.reviews',
'swell inspect content custom.admin.products',
'swell inspect content reviews --app=honest_reviews',
'swell inspect content --live',
];
resourceLabel = 'Content views';
resourceLabelSingular = 'content view';
adminPath = '/data/:content';
commandName = 'content';
async run() {
const { args, flags } = await this.parse(Content);
await this.runInspect({ args, flags });
}
keyFor(record, appSlugById) {
return resolveContentKey(record.id, appSlugById);
}
groupForRecord(record, appSlugById) {
return groupContentRecord(record, appSlugById);
}
async showDetail(identifier, scope, flags) {
const unresolved = await reverseResolveContentId(identifier, scope, (slug) => resolveAppId(this.api, slug));
const record = await this.api.get({
adminPath: `${this.adminPath}/${unresolved}`,
});
if (!record) {
this.throwNotFound(identifier);
}
this.emitDetail(record, flags);
}
}