-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdetails.ts
More file actions
101 lines (88 loc) · 2.84 KB
/
details.ts
File metadata and controls
101 lines (88 loc) · 2.84 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Command from "../../core/command";
import {
flags,
FlagInput,
managementSDKClient,
cliux,
printFlagDeprecation,
} from "@contentstack/cli-utilities";
import buildOutput from "../../core/content-type/details";
import { getStack, getContentType } from "../../utils";
export default class DetailsCommand extends Command {
static description = "Display Content Type details";
static examples = [
'$ csdx content-type:details --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page"',
'$ csdx content-type:details --alias "management token" --content-type "home_page"',
'$ csdx content-type:details --alias "management token" --content-type "home_page" --no-path',
];
static flags: any = {
stack: flags.string({
char: "s",
description: "Stack UID",
exclusive: ["token-alias"],
parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]),
}),
"stack-api-key": flags.string({
char: "k",
description: "Stack API Key",
exclusive: ["token-alias"],
}),
"token-alias": flags.string({
char: "a",
description: "Management token alias",
parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]),
}),
alias: flags.string({
char: "a",
description: "Alias of the management token",
}),
"content-type": flags.string({
char: "c",
description: "Content Type UID",
required: true,
parse: printFlagDeprecation(["-c"], ["--content-type"]),
}),
path: flags.boolean({
char: "p",
description: "show path column",
default: true,
allowNo: true,
parse: printFlagDeprecation(["-p"], ["--path"]),
}),
};
async run() {
try {
const { flags } = await this.parse(DetailsCommand);
await this.setup(flags);
this.contentTypeManagementClient = await managementSDKClient({
host: this.cmaHost,
"X-CS-CLI": this.context?.analyticsInfo,
});
const spinner = cliux.loaderV2(Command.RequestDataMessage);
const [stack, contentType, references] = await Promise.all([
getStack(this.contentTypeManagementClient, this.apiKey, spinner),
getContentType({
managementSdk: this.contentTypeManagementClient,
apiKey: this.apiKey,
uid: flags["content-type"],
spinner,
}),
this.client.getContentTypeReferences(
this.apiKey,
flags["content-type"],
spinner
),
]);
cliux.loaderV2("", spinner);
const output = buildOutput(contentType, references, {
showPath: flags.path,
});
this.printOutput(output, "details", flags["content-type"], stack.name);
} catch (error: any) {
this.error(error?.message || "An error occurred.", {
exit: 1,
suggestions: error.suggestions,
});
}
}
}