|
1 | 1 | import {Command} from '@contentstack/cli-command' |
2 | | -import { BuildOutput } from '../core/content-type/build-output'; |
| 2 | +import {BuildOutput} from '../core/content-type/build-output' |
3 | 3 | import ContentstackClient from '../core/contentstack/client' |
4 | 4 |
|
5 | 5 | export default class ContentTypeCommand extends Command { |
6 | | - protected apiKey!: string; |
| 6 | + protected static RequestDataMessage = 'Requesting data'; |
| 7 | + protected apiKey!: string; |
| 8 | + protected client!: ContentstackClient; |
7 | 9 |
|
8 | | - protected client!: ContentstackClient; |
9 | | - |
10 | | - setup(flags: any) { |
11 | | - if (!this.authToken) { |
12 | | - this.error('You need to login, first. See: auth:login --help', {exit: 2, suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/']}) |
13 | | - } |
14 | | - |
15 | | - if (!flags['token-alias'] && !flags.stack) { |
16 | | - this.error('You must provide either a token alias or a Stack UID.', {exit: 2}) |
17 | | - } |
| 10 | + setup(flags: any) { |
| 11 | + if (!this.authToken) { |
| 12 | + this.error('You need to login, first. See: auth:login --help', {exit: 2, suggestions: ['https://www.contentstack.com/docs/developers/cli/authentication/']}) |
| 13 | + } |
18 | 14 |
|
19 | | - if (flags['token-alias']) { |
20 | | - const token = this.getToken(flags['token-alias']) |
| 15 | + if (!flags['token-alias'] && !flags.stack) { |
| 16 | + this.error('You must provide either a token alias or a Stack UID.', {exit: 2}) |
| 17 | + } |
21 | 18 |
|
22 | | - if (token.type !== 'management') { |
23 | | - this.warn('Possibly using a delivery token. You may not be able to connect to your Stack. Please use a management token.') |
24 | | - } |
| 19 | + if (flags['token-alias']) { |
| 20 | + const token = this.getToken(flags['token-alias']) |
25 | 21 |
|
26 | | - this.apiKey = token.apiKey |
27 | | - } else { |
28 | | - this.apiKey = flags.stack as string |
| 22 | + if (token.type !== 'management') { |
| 23 | + this.warn('Possibly using a delivery token. You may not be able to connect to your Stack. Please use a management token.') |
29 | 24 | } |
30 | 25 |
|
31 | | - this.client = new ContentstackClient(this.cmaHost, this.authToken) |
| 26 | + this.apiKey = token.apiKey |
| 27 | + } else { |
| 28 | + this.apiKey = flags.stack as string |
32 | 29 | } |
33 | 30 |
|
34 | | - printOutput(output: BuildOutput, who: string, what: string | null, where: string) { |
35 | | - this.log(`Displaying ${who} ${what ? `for ${what}` : ''} on '${where}.'`) |
36 | | - this.log('---\n') |
| 31 | + this.client = new ContentstackClient(this.cmaHost, this.authToken) |
| 32 | + } |
| 33 | + |
| 34 | + printOutput(output: BuildOutput, who: string, what: string | null, where: string) { |
| 35 | + this.log(`Requested ${who}${what ? ` for ${what} ` : ' '}on '${where}.'`) |
| 36 | + this.log('---\n') |
37 | 37 |
|
38 | | - if (output.hasResults) { |
39 | | - if (output.header) { |
40 | | - this.log(output.header) |
41 | | - } |
| 38 | + if (output.hasResults) { |
| 39 | + if (output.header) { |
| 40 | + this.log(output.header) |
| 41 | + } |
42 | 42 |
|
43 | | - if (output.body) { |
44 | | - this.log(output.body) |
45 | | - } |
| 43 | + if (output.body) { |
| 44 | + this.log(output.body) |
| 45 | + } |
46 | 46 |
|
47 | | - if (output.footer) { |
48 | | - this.log(output.footer) |
49 | | - } |
50 | | - } else { |
51 | | - this.log(`No ${who} found.`) |
| 47 | + if (output.footer) { |
| 48 | + this.log(output.footer) |
52 | 49 | } |
| 50 | + } else { |
| 51 | + this.log(`No ${who} found.`) |
53 | 52 | } |
| 53 | + } |
54 | 54 | } |
0 commit comments