diff --git a/packages/imperative/src/utilities/__tests__/CliUtils.unit.test.ts b/packages/imperative/src/utilities/__tests__/CliUtils.unit.test.ts index 6d3bd5094d..98dcfdfcd3 100644 --- a/packages/imperative/src/utilities/__tests__/CliUtils.unit.test.ts +++ b/packages/imperative/src/utilities/__tests__/CliUtils.unit.test.ts @@ -187,7 +187,7 @@ describe("CliUtils", () => { let responseErrText: string = notSetYet; // create a fake set of command handler parameters - const handlerParms: any = { + let handlerParms: any = { definition: { deprecatedReplacement: "Something must be better" }, @@ -234,6 +234,13 @@ describe("CliUtils", () => { CliUtils.showMsgWhenDeprecated(handlerParms); expect(responseErrText).toEqual(notSetYet); }); + + it("should produce alternative text when deprecatedReplacement is an empty string", () => { + responseErrText = notSetYet; + handlerParms.definition.deprecatedReplacement = ""; + CliUtils.showMsgWhenDeprecated(handlerParms); + expect(responseErrText).toContain("Obsolete component. No replacement exists"); + }); }); describe("buildBaseArgs", () => { diff --git a/packages/imperative/src/utilities/src/CliUtils.ts b/packages/imperative/src/utilities/src/CliUtils.ts index 8082613889..1d6d7a696e 100644 --- a/packages/imperative/src/utilities/src/CliUtils.ts +++ b/packages/imperative/src/utilities/src/CliUtils.ts @@ -377,20 +377,26 @@ export class CliUtils { * @memberof CliUtils */ public static showMsgWhenDeprecated(handlerParms: IHandlerParameters) { - if (handlerParms.definition.deprecatedReplacement) { + let oldCmd: string | number; + if (handlerParms.definition.deprecatedReplacement || handlerParms.definition.deprecatedReplacement === "") { // form the command that is deprecated - let oldCmd: string | number; - if (handlerParms.positionals.length >= 1) { - oldCmd = handlerParms.positionals[0]; + if(handlerParms.definition.deprecatedReplacement === "") + { + handlerParms.response.console.error("\nObsolete component. No replacement exists"); } - if (handlerParms.positionals.length >= 2) { - oldCmd = oldCmd + " " + handlerParms.positionals[1]; - } - - // display the message + else + { + if (handlerParms.positionals.length >= 1) { + oldCmd = handlerParms.positionals[0]; + } + if (handlerParms.positionals.length >= 2) { + oldCmd = oldCmd + " " + handlerParms.positionals[1]; + } + // display the message handlerParms.response.console.error("\nWarning: The command '" + oldCmd + "' is deprecated."); handlerParms.response.console.error("Recommended replacement: " + handlerParms.definition.deprecatedReplacement); + } } }