1- import { Flags } from '@oclif/core' ;
1+ import { Help } from '@oclif/core' ;
22import { BaseCommand } from '../../base-command' ;
3- import { CLITable , FlagInput , configHandler , cliux , log , handleAndLogError , TableFlags } from '@contentstack/cli-utilities' ;
3+ import { CLITable , FlagInput } from '@contentstack/cli-utilities' ;
44
55export default class TokensCommand extends BaseCommand < typeof TokensCommand > {
66 static description = 'Manage authentication tokens for API access' ;
7+ static strict = false ;
78
89 static examples = [
910 '$ csdx tokens:list' ,
@@ -22,63 +23,8 @@ export default class TokensCommand extends BaseCommand<typeof TokensCommand> {
2223 ] ) ;
2324
2425 async run ( ) : Promise < any > {
25- const { flags } = await this . parse ( TokensCommand ) ;
26-
27- log . debug ( 'TokensCommand run method started.' , this . contextDetails ) ;
28- this . contextDetails . module = 'tokens-list' ;
29-
30- try {
31- log . debug ( 'Retrieving tokens from configuration.' , this . contextDetails ) ;
32- const managementTokens = configHandler . get ( 'tokens' ) ;
33- log . debug ( 'Tokens retrieved from configuration.' , { ...this . contextDetails , tokenCount : managementTokens ? Object . keys ( managementTokens ) . length : 0 } ) ;
34-
35- const tokens : Record < string , unknown > [ ] = [ ] ;
36- if ( managementTokens && Object . keys ( managementTokens ) . length > 0 ) {
37- log . debug ( 'Processing tokens for display.' , this . contextDetails ) ;
38- Object . keys ( managementTokens ) . forEach ( function ( item ) {
39- tokens . push ( {
40- alias : item ,
41- token : managementTokens [ item ] . token ,
42- apiKey : managementTokens [ item ] . apiKey ,
43- environment : managementTokens [ item ] . environment ? managementTokens [ item ] . environment : '-' ,
44- type : managementTokens [ item ] . type ,
45- } ) ;
46- log . debug ( `Token processed: ${ item } ` , { tokenType : managementTokens [ item ] . type } ) ;
47- } ) ;
48-
49- log . debug ( 'Token list flags parsed.' , { ...this . contextDetails , flags } ) ;
50-
51- const headers = [
52- {
53- value : 'alias' ,
54- } ,
55- {
56- value : 'token' ,
57- } ,
58- {
59- value : 'apiKey' ,
60- } ,
61- {
62- value : 'environment' ,
63- } ,
64- {
65- value : 'type' ,
66- } ,
67- ] ;
68-
69- log . debug ( 'Displaying token table.' , { ...this . contextDetails , tokenCount : tokens . length } ) ;
70- cliux . table ( headers , tokens , flags as TableFlags ) ;
71- log . debug ( 'Token table displayed successfully.' , this . contextDetails ) ;
72- } else {
73- log . debug ( 'No tokens found in configuration.' , this . contextDetails ) ;
74- this . log ( 'No tokens found. Add one using "csdx tokens:add"' ) ;
75- }
76-
77- log . debug ( 'Token list command completed successfully.' , this . contextDetails ) ;
78- } catch ( error ) {
79- log . debug ( 'Token list command failed.' , { ...this . contextDetails , error } ) ;
80- this . log ( 'Failed to list tokens' ) ;
81- handleAndLogError ( error , { ...this . contextDetails } ) ;
82- }
26+ await this . parse ( TokensCommand , this . argv . filter ( ( a ) => a !== '-help' ) ) ;
27+ const cmd = this . config . findCommand ( 'tokens' ) ;
28+ if ( cmd ) await new Help ( this . config ) . showCommandHelp ( cmd ) ;
8329 }
8430}
0 commit comments