Skip to content

Commit 37fc911

Browse files
committed
standardizing output
1 parent e9e5757 commit 37fc911

File tree

11 files changed

+75
-55
lines changed

11 files changed

+75
-55
lines changed

src/commands/command.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
import {Command} from '@contentstack/cli-command'
2-
import { BuildOutput } from '../core/content-type/build-output';
2+
import {BuildOutput} from '../core/content-type/build-output'
33
import ContentstackClient from '../core/contentstack/client'
44

55
export default class ContentTypeCommand extends Command {
6-
protected apiKey!: string;
6+
protected static RequestDataMessage = 'Requesting data';
7+
protected apiKey!: string;
8+
protected client!: ContentstackClient;
79

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+
}
1814

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+
}
2118

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'])
2521

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.')
2924
}
3025

31-
this.client = new ContentstackClient(this.cmaHost, this.authToken)
26+
this.apiKey = token.apiKey
27+
} else {
28+
this.apiKey = flags.stack as string
3229
}
3330

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')
3737

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+
}
4242

43-
if (output.body) {
44-
this.log(output.body)
45-
}
43+
if (output.body) {
44+
this.log(output.body)
45+
}
4646

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)
5249
}
50+
} else {
51+
this.log(`No ${who} found.`)
5352
}
53+
}
5454
}

src/commands/content-type/audit.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Command from '../command'
22
import {flags} from '@contentstack/cli-command'
3+
import cli from 'cli-ux'
34
import buildOutput from '../../core/content-type/audit'
45

56
export default class AuditCommand extends Command {
@@ -37,12 +38,16 @@ export default class AuditCommand extends Command {
3738
const {flags} = this.parse(AuditCommand)
3839
this.setup(flags)
3940

41+
cli.action.start(Command.RequestDataMessage)
42+
4043
const [stack, audit, users] = await Promise.all([
4144
this.client.getStack(this.apiKey),
4245
this.client.getContentTypeAuditLogs(this.apiKey, flags['content-type']),
4346
this.client.getUsers(this.apiKey),
4447
])
4548

49+
cli.action.stop()
50+
4651
const output = buildOutput(audit.logs, users)
4752
this.printOutput(output, 'Audit Logs', flags['content-type'], stack.name)
4853
} catch (error) {

src/commands/content-type/compare.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Command from '../command'
22
import {flags} from '@contentstack/cli-command'
3+
import cli from 'cli-ux'
34
import buildOutput from '../../core/content-type/compare'
45

56
export default class CompareCommand extends Command {
@@ -51,12 +52,16 @@ export default class CompareCommand extends Command {
5152
const {flags} = this.parse(CompareCommand)
5253
this.setup(flags)
5354

55+
cli.action.start(Command.RequestDataMessage)
56+
5457
const [stack, previous, current] = await Promise.all([
5558
this.client.getStack(this.apiKey),
5659
this.client.getContentType(this.apiKey, flags['content-type'], true, flags.left),
5760
this.client.getContentType(this.apiKey, flags['content-type'], true, flags.right),
5861
])
5962

63+
cli.action.stop()
64+
6065
const output = await buildOutput(flags['content-type'], previous, current)
6166
this.printOutput(output, 'changes', flags['content-type'], stack.name)
6267
} catch (error) {

src/commands/content-type/details.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Command from '../command'
22
import {flags} from '@contentstack/cli-command'
33
import buildOutput from '../../core/content-type/details'
4+
import cli from 'cli-ux'
45

56
export default class DetailsCommand extends Command {
67
static description = 'display Content Type details';
@@ -37,12 +38,16 @@ export default class DetailsCommand extends Command {
3738
const {flags} = this.parse(DetailsCommand)
3839
this.setup(flags)
3940

41+
cli.action.start(Command.RequestDataMessage)
42+
4043
const [stack, contentType, references] = await Promise.all([
4144
this.client.getStack(this.apiKey),
4245
this.client.getContentType(this.apiKey, flags['content-type'], true),
4346
this.client.getContentTypeReferences(this.apiKey, flags['content-type']),
4447
])
4548

49+
cli.action.stop()
50+
4651
const output = buildOutput(contentType, references)
4752
this.printOutput(output, 'details', flags['content-type'], stack.name)
4853
} catch (error) {

src/commands/content-type/list.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Command from '../command'
22
import {flags} from '@contentstack/cli-command'
3+
import cli from 'cli-ux'
34
import buildOutput from '../../core/content-type/list'
45

56
export default class ListCommand extends Command {
@@ -40,11 +41,15 @@ export default class ListCommand extends Command {
4041
const {flags} = this.parse(ListCommand)
4142
this.setup(flags)
4243

44+
cli.action.start(Command.RequestDataMessage)
45+
4346
const [stack, contentTypes] = await Promise.all([
4447
this.client.getStack(this.apiKey),
4548
this.client.getContentTypes(this.apiKey, false),
4649
])
4750

51+
cli.action.stop()
52+
4853
const output = buildOutput(contentTypes, flags.order)
4954
this.printOutput(output, 'Content Types', null, stack.name)
5055
} catch (error) {

src/core/content-type/audit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as tableImport from 'table'
2-
import { BuildOutput } from './build-output'
2+
import {BuildOutput} from './build-output'
33
import * as format from './formatting'
44

55
const {table} = tableImport
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type BuildOutput = {
2-
header: string | null,
3-
body: string,
4-
footer: string | null,
5-
hasResults: boolean
6-
}
2+
header: string | null;
3+
body: string;
4+
footer: string | null;
5+
hasResults: boolean;
6+
}

src/core/content-type/compare.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from 'fs'
33
import * as tmp from 'tmp'
44
import * as Diff2html from 'diff2html'
55
import gitDiff from 'git-diff'
6-
import { BuildOutput } from './build-output'
6+
import {BuildOutput} from './build-output'
77

88
export default async function buildOutput(contentTypeName: string, previous: any, current: any): Promise<BuildOutput> {
99
const diffString = buildDiffString(previous, current)
@@ -24,7 +24,7 @@ export default async function buildOutput(contentTypeName: string, previous: any
2424
header: null,
2525
body: 'Please check the browser output.',
2626
footer: null,
27-
hasResults: true
27+
hasResults: true,
2828
}
2929
}
3030

src/core/content-type/details.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as tableImport from 'table'
2-
import { BuildOutput } from './build-output'
2+
import {BuildOutput} from './build-output'
33
import * as format from './formatting'
44

55
const {table} = tableImport

src/core/content-type/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as tableImport from 'table'
2-
import { BuildOutput } from './build-output'
2+
import {BuildOutput} from './build-output'
33
import * as format from './formatting'
44

55
const {table} = tableImport

0 commit comments

Comments
 (0)