-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathlist.ts
More file actions
77 lines (63 loc) · 2.32 KB
/
list.ts
File metadata and controls
77 lines (63 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import {ux} from '@oclif/core';
import {InstanceCommand, createTable, type ColumnDef} from '@salesforce/b2c-tooling-sdk/cli';
import {listCodeVersions, type CodeVersion, type CodeVersionResult} from '@salesforce/b2c-tooling-sdk/operations/code';
import {t} from '../../i18n/index.js';
const COLUMNS: Record<string, ColumnDef<CodeVersion>> = {
id: {
header: 'ID',
get: (v) => v.id || '-',
},
active: {
header: 'Active',
get: (v) => (v.active ? 'Yes' : 'No'),
},
rollback: {
header: 'Rollback',
get: (v) => (v.rollback ? 'Yes' : 'No'),
},
lastModified: {
header: 'Last Modified',
get: (v) => (v.last_modification_time ? new Date(v.last_modification_time).toLocaleString() : '-'),
},
cartridges: {
header: 'Cartridges',
get: (v) => String(v.cartridges?.length ?? 0),
},
};
const DEFAULT_COLUMNS = ['id', 'active', 'rollback', 'lastModified', 'cartridges'];
export default class CodeList extends InstanceCommand<typeof CodeList> {
static description = t('commands.code.list.description', 'List code versions on a B2C Commerce instance');
static enableJsonFlag = true;
static examples = [
'<%= config.bin %> <%= command.id %>',
'<%= config.bin %> <%= command.id %> --server my-sandbox.demandware.net',
'<%= config.bin %> <%= command.id %> --json',
];
async run(): Promise<CodeVersionResult> {
this.requireOAuthCredentials();
const hostname = this.resolvedConfig.values.hostname!;
this.log(t('commands.code.list.fetching', 'Fetching code versions from {{hostname}}...', {hostname}));
const versions = await listCodeVersions(this.instance);
const result: CodeVersionResult = {
count: versions.length,
data: versions,
total: versions.length,
};
// In JSON mode, just return the data - oclif handles output to stdout
if (this.jsonEnabled()) {
return result;
}
// Human-readable table output to stdout
if (versions.length === 0) {
ux.stdout(t('commands.code.list.noVersions', 'No code versions found.'));
return result;
}
createTable(COLUMNS).render(versions, DEFAULT_COLUMNS);
return result;
}
}