1- import { Command , flags } from '@oclif/ command'
1+ import { Command , flags } from '@contentstack/cli- command'
22import getAuthToken from '../../../utils/get-auth-token'
33import { inquireAlias , inquireModule } from '../../../utils/interactive'
4- import getManagementToken from '../../../utils/get-management-token'
54import connectStack from '../../../utils/connect-stack'
65const regexMessages = require ( '../../../../messages/index.json' ) . validateRegex
76
87export default class CmStacksValidateRegex extends Command {
9- static description = 'This command is used to check for all the invalid regexes present in the content types and global fields of your stack.'
8+ static description = regexMessages . command . description
109
1110 static flags = {
12- help : flags . help ( { char : 'h' } ) ,
13- alias : flags . string ( { char : 'a' , description : 'Alias to the token for referring it with other commands' } ) ,
14- contentType : flags . boolean ( { char : 'c' , description : 'To check invalid regexes within the content types' } ) ,
15- globalField : flags . boolean ( { char : 'g' , description : 'To check invalid regexes within the global fields' } ) ,
16- filePath : flags . string ( { char : 'f' , description : 'The path or the location in your file system where the CSV output file should be stored, e.g., -f "C:\\Users\\Name\\Desktop\\cli\\csv"' } ) ,
11+ help : flags . help ( { char : 'h' , description : regexMessages . command . help } ) ,
12+ alias : flags . string ( { char : 'a' , description : regexMessages . command . alias } ) ,
13+ contentType : flags . boolean ( { char : 'c' , description : regexMessages . command . contentTypes } ) ,
14+ globalField : flags . boolean ( { char : 'g' , description : regexMessages . command . globalFields } ) ,
15+ filePath : flags . string ( { char : 'f' , description : regexMessages . command . filePath } ) ,
1716 }
1817
19- static usage = '$ csdx cm:stacks:validate-regex --alias=[ALIAS_NAME] --contentType --globalField --filePath=[FILE_PATH]'
20-
2118 static examples = [
2219 '$ csdx cm:stacks:validate-regex' ,
23- '$ csdx cm:stacks:validate-regex --alias=\'Alias Name\' -a \'Alias Name\'' ,
24- '$ csdx cm:stacks:validate-regex --contentType -c' ,
25- '$ csdx cm:stacks:validate-regex --globalField -g' ,
26- '$ csdx cm:stacks:validate-regex --filePath=\'path/to/the/directory/\' -f \'path/to/the/directory/\'' ,
27- '$ csdx cm:stacks:validate-regex --alias=\'Alias Name\' --contentType --globalField' ,
28- '$ csdx cm:stacks:validate-regex --alias=\'Alias Name\' --contentType --globalField --filePath=\'path/to/the/directory/\'' ,
29- '$ csdx cm:stacks:validate-regex -a \'Alias Name\' -c -g' ,
30- '$ csdx cm:stacks:validate-regex -a \'Alias Name\' -c -g -f \'path/to/the/directory/\'' ,
31- '$ csdx cm:stacks:validate-regex -cga \'Alias Name\'' ,
32- '$ csdx cm:stacks:validate-regex -cga \'Alias Name\' -f \'path/to/the/directory/\'' ,
20+ '$ csdx cm:stacks:validate-regex -a <management_token_alias>' ,
21+ '$ csdx cm:stacks:validate-regex -c' ,
22+ '$ csdx cm:stacks:validate-regex -g' ,
23+ '$ csdx cm:stacks:validate-regex -f <path/to/the/directory>' ,
24+ '$ csdx cm:stacks:validate-regex -a <management_token_alias> -c -g' ,
25+ '$ csdx cm:stacks:validate-regex -a <management_token_alias> -c -g -f <path/to/the/directory>' ,
3326 ]
3427
3528 async run ( ) {
@@ -40,26 +33,26 @@ export default class CmStacksValidateRegex extends Command {
4033 authToken = await getAuthToken ( )
4134 } catch ( error ) {
4235 this . error ( regexMessages . errors . login , {
43- ref : 'https://www.contentstack.com/docs/developers/cli/authenticate-with-the-cli/# login' ,
36+ ref : regexMessages . command . login ,
4437 } )
4538 }
4639
4740 await inquireAlias ( flags )
4841
4942 let tokenDetails : any
5043 try {
51- tokenDetails = await getManagementToken ( flags . alias )
44+ tokenDetails = await this . getToken ( flags . alias )
5245 } catch ( error ) {
5346 this . error ( regexMessages . errors . tokenNotFound , {
54- ref : 'https://www.contentstack.com/docs/developers/cli/authenticate-with-the-cli/#add-management-token' ,
47+ ref : regexMessages . command . addManagementToken ,
5548 } )
5649 }
5750
5851 await inquireModule ( flags )
5952
6053 try {
6154 await connectStack ( flags , authToken , tokenDetails . apiKey )
62- } catch ( error : any ) {
55+ } catch ( error ) {
6356 this . error ( regexMessages . errors . stack . fetch )
6457 }
6558 }
0 commit comments