Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: 0f2e17618b7c8286c5f76d4e25a98b830d3eb2d29acc6f8099f3501ff150d4f4
checksum: a72a1c8e7109e8eb3a4159b7945e20cdb25a99bff32e45fcbf5a6b4534bdb0da
- filename: packages/contentstack-utilities/src/message-handler.ts
checksum: e7221e8413005b9efe3a230cd91aff130850976addc41c0acb10745a56ec3245
version: '1.0'
21 changes: 12 additions & 9 deletions packages/contentstack-auth/src/commands/auth/tokens/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
static examples = ['$ csdx auth:tokens:remove', '$ csdx auth:tokens:remove -a <alias>'];
static flags: FlagInput = {
alias: flags.string({ char: 'a', description: 'Alias (name) of the token to delete.' }),
ignore: flags.boolean({ char: 'i', description: 'Ignores if the token is not present.' }),
};

async run(): Promise<any> {
Expand All @@ -17,21 +16,25 @@ export default class TokensRemoveCommand extends BaseCommand<typeof TokensRemove
log.debug('Token removal flags parsed.', {...this.contextDetails, flags: removeTokenFlags });

const alias = removeTokenFlags.alias;
const ignore = removeTokenFlags.ignore;
log.debug('Token removal parameters set.', {...this.contextDetails, alias, ignore });

log.debug('Token removal parameters set.', {...this.contextDetails, alias });

try {
log.debug('Retrieving token from configuration.', {...this.contextDetails, alias });
const token = configHandler.get(`tokens.${alias}`);
log.debug('Token retrieved from configuration.', {...this.contextDetails, hasToken: !!token, tokenType: token?.type });


if (alias && !token) {
log.debug('Alias provided but token not found.', {...this.contextDetails, alias });
return cliux.print(`No token found with alias '${alias}'.`, { color: 'yellow' });
}

const tokens = configHandler.get('tokens');
log.debug('All tokens retrieved from configuration.', {...this.contextDetails, tokenCount: tokens ? Object.keys(tokens).length : 0 });

const tokenOptions: Array<string> = [];
if (token || ignore) {
log.debug('Token found, or ignore flag set.', {...this.contextDetails, hasToken: !!token, ignore });

if (token) {
log.debug('Token found.', {...this.contextDetails, hasToken: !!token });
configHandler.delete(`tokens.${alias}`);
log.debug('Token removed from configuration.', {...this.contextDetails, alias });
return cliux.success(`CLI_AUTH_TOKENS_REMOVE_SUCCESS`);
Comment thread
cs-raj marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ describe('Tokens Remove Command', () => {
expect(Boolean(config.get(`${configKeyTokens}.${token1Alias}`))).to.be.false;
});

it('Remove the token with invalid alias, should list the table', async function () {
it('Remove the token with invalid alias, should print error and not show interactive picker', async function () {
// Skip this test in PREPACK_MODE - config handler uses in-memory store that doesn't persist properly
if (isPrepackMode) {
this.skip();
return;
}
const inquireStub = sinon.stub(cliux, 'inquire').resolves([]);
const printStub = sinon.stub(cliux, 'print');
await TokensRemoveCommand.run(['-a', 'invalid-test-tokens-remove']);
expect(inquireStub.calledOnce).to.be.true;
expect(printStub.calledOnce).to.be.true;
expect(printStub.firstCall.args[0]).to.include('invalid-test-tokens-remove');
expect(inquireStub.called).to.be.false;
});

it('Selectes multiple token, remove all the selected tokens', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default class RegionSetCommand extends BaseCommand<typeof RegionSetComman
dependsOn: ['cda', 'cma', 'name'],
}),
name: _flags.string({
char: 'n',
description: 'Name for the region, if this flag is added then cda, cma and ui-host flags are required',
dependsOn: ['cda', 'cma', 'ui-host'],
}),
Expand Down
Loading
Loading