@sap/cli-core
Version:
Command-Line Interface (CLI) Core Module
35 lines (34 loc) • 1.53 kB
JavaScript
import { get as getLogger } from "../../../logger/index.js";
export const create = (command, errorMessage = "Command failed") => async (cCommand) => {
const { output } = getLogger("handler.root");
const hdlr = await command.handler(cCommand);
return async (...args) => {
try {
await hdlr(...args);
}
catch (err) {
output(errorMessage);
throw err;
}
finally {
if (command.deprecationInfo?.deprecated) {
let message = `WARNING: The command '${command.command}' is deprecated.`;
if (command.deprecationInfo.deprecatedWithWave) {
message =
`WARNING: The command '${command.command}' is deprecated from version ` +
`${command.deprecationInfo.deprecatedWithWave} onwards.`;
}
if (command.deprecationInfo.decommissionedAfterWave) {
message += ` It will be removed after version ${command.deprecationInfo.decommissionedAfterWave}.`;
}
if (command.deprecationInfo.newCommand) {
message += ` Please start using the new command '${command.deprecationInfo.newCommand}'.`;
}
if (command.deprecationInfo.sapHelpUrl) {
message += ` See ${command.deprecationInfo.sapHelpUrl} for more information.`;
}
output(message);
}
}
};
};