Skip to content

Commit c1bd225

Browse files
committed
making path optional; default compare to recent change
1 parent 37fc911 commit c1bd225

File tree

8 files changed

+82
-18
lines changed

8 files changed

+82
-18
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ _See code: [src/commands/command.ts](https://github.com/Contentstack-Solutions/c
5555

5656
## `csdx content-type:audit`
5757

58-
display audit logs for recent changes to a Content Type
58+
display Audit Logs for recent changes to a Content Type
5959

6060
```
6161
USAGE
@@ -84,14 +84,14 @@ USAGE
8484
OPTIONS
8585
-a, --token-alias=token-alias management token alias
8686
-c, --content-type=content-type (required) Content Type UID
87-
-l, --left=left (required) previous Content Type version
88-
-r, --right=right (required) current Content Type version
87+
-l, --left=left (required) Content Type version
88+
-r, --right=right (required) Content Type version
8989
-s, --stack=stack stack uid
9090
9191
EXAMPLES
9292
$ csdx content-type:compare -s "xxxxxxxxxxxxxxxxxxx" -c "home_page"
93-
$ csdx content-type:compare -s "xxxxxxxxxxxxxxxxxxx" -c "home_page" -left # -right #
94-
$ csdx content-type:compare -a "management token" -c "home_page" -left # -right #
93+
$ csdx content-type:compare -s "xxxxxxxxxxxxxxxxxxx" -c "home_page" -l # -r #
94+
$ csdx content-type:compare -a "management token" -c "home_page" -l # -r #
9595
```
9696

9797
_See code: [src/commands/content-type/compare.ts](https://github.com/Contentstack-Solutions/contentstack-cli-content-type/blob/v1.0.0/src/commands/content-type/compare.ts)_
@@ -107,11 +107,13 @@ USAGE
107107
OPTIONS
108108
-a, --token-alias=token-alias management token alias
109109
-c, --content-type=content-type (required) Content Type UID
110+
-p, --[no-]path show path column
110111
-s, --stack=stack stack uid
111112
112113
EXAMPLES
113114
$ csdx content-type:details -s "xxxxxxxxxxxxxxxxxxx" -c "home_page"
114115
$ csdx content-type:details -a "management token" -c "home_page"
116+
$ csdx content-type:details -a "management token" -c "home_page" --no-path
115117
```
116118

117119
_See code: [src/commands/content-type/details.ts](https://github.com/Contentstack-Solutions/contentstack-cli-content-type/blob/v1.0.0/src/commands/content-type/details.ts)_

oclif.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"1.0.0","commands":{"command":{"id":"command","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"flags":{},"args":[]},"":{"id":"","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"flags":{},"args":[]},"content-type:audit":{"id":"content-type:audit","description":"display audit logs for recent changes to a Content Type","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:audit -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\"","$ csdx content-type:audit -a \"management token\" -c \"home_page\""],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","required":false},"content-type":{"name":"content-type","type":"option","char":"c","description":"Content Type UID","required":true}},"args":[]},"content-type:compare":{"id":"content-type:compare","description":"compare two Content Type versions","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:compare -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\"","$ csdx content-type:compare -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\" -left # -right #","$ csdx content-type:compare -a \"management token\" -c \"home_page\" -left # -right #"],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","hidden":false,"required":false},"content-type":{"name":"content-type","type":"option","char":"c","description":"Content Type UID","required":true},"left":{"name":"left","type":"option","char":"l","description":"previous Content Type version","required":true},"right":{"name":"right","type":"option","char":"r","description":"current Content Type version","required":true}},"args":[]},"content-type:details":{"id":"content-type:details","description":"display Content Type details","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:details -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\"","$ csdx content-type:details -a \"management token\" -c \"home_page\""],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","required":false},"content-type":{"name":"content-type","type":"option","char":"c","description":"Content Type UID","required":true}},"args":[]},"content-type:list":{"id":"content-type:list","description":"list all Content Types in a Stack","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:list -s \"xxxxxxxxxxxxxxxxxxx\"","$ csdx content-type:list -a \"management token\"","$ csdx content-type:list -a \"management token\" -o modified"],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","required":false},"order":{"name":"order","type":"option","char":"o","description":"order by column","required":false,"options":["title","modified"],"default":"title"}},"args":[]}}}
1+
{"version":"1.0.0","commands":{"command":{"id":"command","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"flags":{},"args":[]},"":{"id":"","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"flags":{},"args":[]},"content-type:audit":{"id":"content-type:audit","description":"display Audit Logs for recent changes to a Content Type","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:audit -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\"","$ csdx content-type:audit -a \"management token\" -c \"home_page\""],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","required":false},"content-type":{"name":"content-type","type":"option","char":"c","description":"Content Type UID","required":true}},"args":[]},"content-type:compare":{"id":"content-type:compare","description":"compare two Content Type versions","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:compare -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\"","$ csdx content-type:compare -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\" -l # -r #","$ csdx content-type:compare -a \"management token\" -c \"home_page\" -l # -r #"],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","hidden":false,"required":false},"content-type":{"name":"content-type","type":"option","char":"c","description":"Content Type UID","required":true},"left":{"name":"left","type":"option","char":"l","description":"Content Type version","required":true},"right":{"name":"right","type":"option","char":"r","description":"Content Type version","required":true}},"args":[]},"content-type:details":{"id":"content-type:details","description":"display Content Type details","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:details -s \"xxxxxxxxxxxxxxxxxxx\" -c \"home_page\"","$ csdx content-type:details -a \"management token\" -c \"home_page\"","$ csdx content-type:details -a \"management token\" -c \"home_page\" --no-path"],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","required":false},"content-type":{"name":"content-type","type":"option","char":"c","description":"Content Type UID","required":true},"path":{"name":"path","type":"boolean","char":"p","description":"show path column","allowNo":true}},"args":[]},"content-type:list":{"id":"content-type:list","description":"list all Content Types in a Stack","pluginName":"contentstack-cli-content-type","pluginType":"core","aliases":[],"examples":["$ csdx content-type:list -s \"xxxxxxxxxxxxxxxxxxx\"","$ csdx content-type:list -a \"management token\"","$ csdx content-type:list -a \"management token\" -o modified"],"flags":{"stack":{"name":"stack","type":"option","char":"s","description":"stack uid","required":false},"token-alias":{"name":"token-alias","type":"option","char":"a","description":"management token alias","required":false},"order":{"name":"order","type":"option","char":"o","description":"order by column","required":false,"options":["title","modified"],"default":"title"}},"args":[]}}}

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@oclif/command": "^1.8.0",
1010
"@oclif/config": "^1.17.0",
1111
"@types/git-diff": "^2.0.0",
12+
"@types/hogan.js": "^3.0.0",
1213
"@types/table": "^6.0.0",
1314
"@types/tmp": "^0.2.0",
1415
"axios": "^0.21.0",

src/commands/command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import ContentstackClient from '../core/contentstack/client'
44

55
export default class ContentTypeCommand extends Command {
66
protected static RequestDataMessage = 'Requesting data';
7+
78
protected apiKey!: string;
9+
810
protected client!: ContentstackClient;
911

1012
setup(flags: any) {

src/commands/content-type/compare.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,16 @@ export default class CompareCommand extends Command {
3636

3737
left: flags.integer({
3838
char: 'l',
39-
description: 'Content Type version',
40-
required: true,
39+
description: 'Content Type version, i.e. prev version',
40+
required: false,
41+
dependsOn: ['right']
4142
}),
4243

4344
right: flags.integer({
4445
char: 'r',
45-
description: 'Content Type version',
46-
required: true,
46+
description: 'Content Type version, i.e. later version',
47+
required: false,
48+
dependsOn: ['left']
4749
}),
4850
}
4951

@@ -53,6 +55,16 @@ export default class CompareCommand extends Command {
5355
this.setup(flags)
5456

5557
cli.action.start(Command.RequestDataMessage)
58+
59+
if (!flags.left) {
60+
const discovery = await this.client.getContentType(this.apiKey, flags['content-type'], false);
61+
const version = discovery.content_type._version;
62+
63+
flags.left = version;
64+
flags.right = version > 1 ? version - 1 : version;
65+
66+
this.log(`Comparing versions: ${flags.left} <-> ${flags.right}.`)
67+
}
5668

5769
const [stack, previous, current] = await Promise.all([
5870
this.client.getStack(this.apiKey),
@@ -64,6 +76,10 @@ export default class CompareCommand extends Command {
6476

6577
const output = await buildOutput(flags['content-type'], previous, current)
6678
this.printOutput(output, 'changes', flags['content-type'], stack.name)
79+
80+
if (flags.left && flags.left === flags.right) {
81+
this.warn('Comparing the same version does not produce useful results.')
82+
}
6783
} catch (error) {
6884
this.error(error, {exit: 1, suggestions: error.suggestions})
6985
}

src/commands/content-type/details.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class DetailsCommand extends Command {
99
static examples = [
1010
'$ csdx content-type:details -s "xxxxxxxxxxxxxxxxxxx" -c "home_page"',
1111
'$ csdx content-type:details -a "management token" -c "home_page"',
12+
'$ csdx content-type:details -a "management token" -c "home_page" --no-path',
1213
];
1314

1415
static flags = {
@@ -31,6 +32,13 @@ export default class DetailsCommand extends Command {
3132
description: 'Content Type UID',
3233
required: true,
3334
}),
35+
36+
path: flags.boolean({
37+
char: 'p',
38+
description: 'show path column',
39+
default: true,
40+
allowNo: true,
41+
}),
3442
}
3543

3644
async run() {
@@ -48,7 +56,7 @@ export default class DetailsCommand extends Command {
4856

4957
cli.action.stop()
5058

51-
const output = buildOutput(contentType, references)
59+
const output = buildOutput(contentType, references, {showPath: flags.path})
5260
this.printOutput(output, 'details', flags['content-type'], stack.name)
5361
} catch (error) {
5462
this.error(error, {exit: 1, suggestions: error.suggestions})

src/core/content-type/details.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import * as format from './formatting'
44

55
const {table} = tableImport
66

7-
export default function buildOutput(contentType: any, references: any): BuildOutput {
7+
let buildOptions = {
8+
showPath: true,
9+
}
10+
11+
export default function buildOutput(contentType: any, references: any, options: any): BuildOutput {
12+
buildOptions = Object.assign(buildOptions, options)
13+
814
const header = buildHeader(contentType.content_type, references.references)
915
const body = buildBody(contentType.content_type.schema)
1016

@@ -19,7 +25,15 @@ export default function buildOutput(contentType: any, references: any): BuildOut
1925
function buildBody(schema: any) {
2026
const rows = []
2127

22-
rows.push(['Display Name', 'UID', 'Data Type', 'Path', 'Required', 'Multiple', 'Unique'])
28+
const headers = [
29+
'Display Name',
30+
'UID',
31+
'Data Type',
32+
buildOptions.showPath ? 'Path' : null,
33+
'Req | Mult | Unique',
34+
].filter(v => v !== null)
35+
36+
rows.push(headers)
2337
rows.push(...processFields(schema))
2438

2539
return {
@@ -59,11 +73,9 @@ function buildRow(field: any, parent = null, depth = 0, prefix = '') {
5973
displayName,
6074
field.uid,
6175
field.data_type,
62-
path,
63-
format.checked(field.mandatory),
64-
format.checked(field.multiple),
65-
format.checked(field.unique),
66-
]
76+
buildOptions.showPath ? path : null,
77+
buildOptionsColumn(field),
78+
].filter(v => v !== null)
6779
}
6880

6981
function buildHeader(contentType: any, references: string[]) {
@@ -88,3 +100,21 @@ function buildHeader(contentType: any, references: string[]) {
88100

89101
return result.join('\n')
90102
}
103+
104+
function buildOptionsColumn(field: any) {
105+
let output = ''
106+
107+
if (field.mandatory) {
108+
output += 'R'
109+
}
110+
111+
if (field.multiple) {
112+
output += 'M'
113+
}
114+
115+
if (field.unique) {
116+
output += 'U'
117+
}
118+
119+
return output
120+
}

0 commit comments

Comments
 (0)