-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidate-regex.ts
62 lines (54 loc) · 1.98 KB
/
validate-regex.ts
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
import { Command } from "@contentstack/cli-command";
import { FlagInput, flags } from '@contentstack/cli-utilities';
import connectStack from "../../../utils/connect-stack";
import { inquireAlias, inquireModule } from "../../../utils/interactive";
const regexMessages = require("../../../../messages/index.json").validateRegex;
export default class ValidateRegex extends Command {
static description = regexMessages.command.description;
static flags: any = {
help: flags.help({ char: "h", description: regexMessages.command.help }),
alias: flags.string({
char: "a",
description: regexMessages.command.alias,
}),
contentType: flags.boolean({
char: "c",
description: regexMessages.command.contentTypes,
}),
globalField: flags.boolean({
char: "g",
description: regexMessages.command.globalFields,
}),
filePath: flags.string({
char: "f",
description: regexMessages.command.filePath,
}),
};
static examples = [
"$ csdx cm:stacks:validate-regex",
"$ csdx cm:stacks:validate-regex -a <management_token_alias>",
"$ csdx cm:stacks:validate-regex -c",
"$ csdx cm:stacks:validate-regex -g",
"$ csdx cm:stacks:validate-regex -f <path/to/the/directory>",
"$ csdx cm:stacks:validate-regex -a <management_token_alias> -c -g",
"$ csdx cm:stacks:validate-regex -a <management_token_alias> -c -g -f <path/to/the/directory>",
];
async run() {
const commandObject = await this.parse(ValidateRegex);
await inquireAlias(commandObject.flags);
let tokenDetails: any;
try {
tokenDetails = await this.getToken(commandObject.flags.alias);
} catch (error) {
this.error(regexMessages.errors.tokenNotFound, {
ref: regexMessages.command.addManagementToken,
});
}
await inquireModule(commandObject.flags);
try {
await connectStack(commandObject.flags, this.cmaHost, tokenDetails);
} catch (error) {
this.error(regexMessages.errors.stack.fetch);
}
}
}