Skip to content

Commit 4808903

Browse files
fix(dx-4439): show human-readable prompts after command correction
1 parent 8b96701 commit 4808903

File tree

3 files changed

+858
-3313
lines changed

3 files changed

+858
-3313
lines changed

packages/contentstack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
],
157157
"hooks": {
158158
"prerun": [
159+
"./lib/hooks/prerun/init-context-for-command",
159160
"./lib/hooks/prerun/command-deprecation-check",
160161
"./lib/hooks/prerun/default-rate-limit-check",
161162
"./lib/hooks/prerun/latest-version-warning"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
cliux,
3+
messageHandler,
4+
managementSDKInitiator,
5+
marketplaceSDKInitiator,
6+
} from '@contentstack/cli-utilities';
7+
import { CsdxContext } from '../../utils';
8+
9+
/**
10+
* When an invalid command is corrected (e.g. loginasda → login), init ran with the invalid
11+
* command so context.messageFilePath was never set. Re-build context and re-init utilities
12+
* for the actual command so i18n prompts show human-readable text.
13+
*/
14+
export default async function (opts: {
15+
Command?: { id?: string };
16+
config?: any;
17+
}): Promise<void> {
18+
const config = opts?.config ?? this.config;
19+
const commandId = opts?.Command?.id;
20+
if (!config?.context?.messageFilePath && commandId) {
21+
config.context = new CsdxContext({ id: commandId }, config);
22+
messageHandler.init(config.context);
23+
cliux.init(config.context);
24+
managementSDKInitiator.init(config.context);
25+
marketplaceSDKInitiator.init(config.context);
26+
}
27+
}

0 commit comments

Comments
 (0)