|
1 | | -import Command from '../../core/command' |
2 | | -import { flags, FlagInput, managementSDKClient, cliux, printFlagDeprecation } from '@contentstack/cli-utilities' |
3 | | -import buildOutput from '../../core/content-type/details' |
4 | | -import { getStack, getContentType } from '../../utils' |
| 1 | +import Command from "../../core/command"; |
| 2 | +import { |
| 3 | + flags, |
| 4 | + FlagInput, |
| 5 | + managementSDKClient, |
| 6 | + cliux, |
| 7 | + printFlagDeprecation, |
| 8 | +} from "@contentstack/cli-utilities"; |
| 9 | +import buildOutput from "../../core/content-type/details"; |
| 10 | +import { getStack, getContentType } from "../../utils"; |
5 | 11 |
|
6 | 12 | export default class DetailsCommand extends Command { |
7 | | - static description = 'Display Content Type details' |
| 13 | + static description = "Display Content Type details"; |
8 | 14 |
|
9 | 15 | static examples = [ |
10 | 16 | '$ csdx content-type:details --stack-api-key "xxxxxxxxxxxxxxxxxxx" --content-type "home_page"', |
11 | 17 | '$ csdx content-type:details --alias "management token" --content-type "home_page"', |
12 | | - '$ csdx content-type:details --alias "management token" --content-type "home_page" --no-path' |
13 | | - ] |
| 18 | + '$ csdx content-type:details --alias "management token" --content-type "home_page" --no-path', |
| 19 | + ]; |
14 | 20 |
|
15 | 21 | static flags: any = { |
16 | 22 | stack: flags.string({ |
17 | | - char: 's', |
18 | | - description: 'Stack UID', |
19 | | - exclusive: ['token-alias'], |
20 | | - parse: printFlagDeprecation(['-s', '--stack'], ['-k', '--stack-api-key']) |
| 23 | + char: "s", |
| 24 | + description: "Stack UID", |
| 25 | + exclusive: ["token-alias"], |
| 26 | + parse: printFlagDeprecation(["-s", "--stack"], ["-k", "--stack-api-key"]), |
21 | 27 | }), |
22 | 28 |
|
23 | | - 'stack-api-key': flags.string({ |
24 | | - char: 'k', |
25 | | - description: 'Stack API Key', |
26 | | - exclusive: ['token-alias'] |
| 29 | + "stack-api-key": flags.string({ |
| 30 | + char: "k", |
| 31 | + description: "Stack API Key", |
| 32 | + exclusive: ["token-alias"], |
27 | 33 | }), |
28 | 34 |
|
29 | | - 'token-alias': flags.string({ |
30 | | - char: 'a', |
31 | | - description: 'Management token alias', |
32 | | - parse: printFlagDeprecation(['--token-alias'], ['-a', '--alias']) |
| 35 | + "token-alias": flags.string({ |
| 36 | + char: "a", |
| 37 | + description: "Management token alias", |
| 38 | + parse: printFlagDeprecation(["--token-alias"], ["-a", "--alias"]), |
33 | 39 | }), |
34 | 40 |
|
35 | 41 | alias: flags.string({ |
36 | | - char: 'a', |
37 | | - description: 'Alias of the management token' |
| 42 | + char: "a", |
| 43 | + description: "Alias of the management token", |
38 | 44 | }), |
39 | 45 |
|
40 | | - 'content-type': flags.string({ |
41 | | - char: 'c', |
42 | | - description: 'Content Type UID', |
| 46 | + "content-type": flags.string({ |
| 47 | + char: "c", |
| 48 | + description: "Content Type UID", |
43 | 49 | required: true, |
44 | | - parse: printFlagDeprecation(['-c'], ['--content-type']) |
| 50 | + parse: printFlagDeprecation(["-c"], ["--content-type"]), |
45 | 51 | }), |
46 | 52 |
|
47 | 53 | path: flags.boolean({ |
48 | | - char: 'p', |
49 | | - description: 'show path column', |
| 54 | + char: "p", |
| 55 | + description: "show path column", |
50 | 56 | default: true, |
51 | 57 | allowNo: true, |
52 | | - parse: printFlagDeprecation(['-p'], ['--path']) |
53 | | - }) |
54 | | - } |
| 58 | + parse: printFlagDeprecation(["-p"], ["--path"]), |
| 59 | + }), |
| 60 | + }; |
55 | 61 |
|
56 | 62 | async run() { |
57 | 63 | try { |
58 | | - const { flags } = await this.parse(DetailsCommand) |
59 | | - this.setup(flags) |
| 64 | + const { flags } = await this.parse(DetailsCommand); |
| 65 | + await this.setup(flags); |
60 | 66 | this.contentTypeManagementClient = await managementSDKClient({ |
61 | 67 | host: this.cmaHost, |
62 | | - 'X-CS-CLI': this.context?.analyticsInfo |
63 | | - }) |
| 68 | + "X-CS-CLI": this.context?.analyticsInfo, |
| 69 | + }); |
64 | 70 |
|
65 | | - const spinner = cliux.loaderV2(Command.RequestDataMessage) |
| 71 | + const spinner = cliux.loaderV2(Command.RequestDataMessage); |
66 | 72 |
|
67 | 73 | const [stack, contentType, references] = await Promise.all([ |
68 | 74 | getStack(this.contentTypeManagementClient, this.apiKey, spinner), |
69 | 75 | getContentType({ |
70 | 76 | managementSdk: this.contentTypeManagementClient, |
71 | 77 | apiKey: this.apiKey, |
72 | | - uid: flags['content-type'], |
73 | | - spinner |
| 78 | + uid: flags["content-type"], |
| 79 | + spinner, |
74 | 80 | }), |
75 | | - this.client.getContentTypeReferences(this.apiKey, flags['content-type'], spinner) |
76 | | - ]) |
| 81 | + this.client.getContentTypeReferences( |
| 82 | + this.apiKey, |
| 83 | + flags["content-type"], |
| 84 | + spinner |
| 85 | + ), |
| 86 | + ]); |
77 | 87 |
|
78 | | - cliux.loaderV2('', spinner) |
| 88 | + cliux.loaderV2("", spinner); |
79 | 89 |
|
80 | 90 | const output = buildOutput(contentType, references, { |
81 | | - showPath: flags.path |
82 | | - }) |
83 | | - this.printOutput(output, 'details', flags['content-type'], stack.name) |
| 91 | + showPath: flags.path, |
| 92 | + }); |
| 93 | + this.printOutput(output, "details", flags["content-type"], stack.name); |
84 | 94 | } catch (error: any) { |
85 | | - this.error(error?.message || 'An error occurred.', { exit: 1, suggestions: error.suggestions }) |
| 95 | + this.error(error?.message || "An error occurred.", { |
| 96 | + exit: 1, |
| 97 | + suggestions: error.suggestions, |
| 98 | + }); |
86 | 99 | } |
87 | 100 | } |
88 | 101 | } |
0 commit comments