Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Replace deprecated commands #2222

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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", () => {
Expand Down
24 changes: 15 additions & 9 deletions packages/imperative/src/utilities/src/CliUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Loading