@backstage/cli
Version:
CLI for developing Backstage plugins and apps
38 lines (35 loc) • 1.15 kB
JavaScript
function createScriptOptionsParser(anyCmd, commandPath) {
let rootCmd = anyCmd;
while (rootCmd.parent) {
rootCmd = rootCmd.parent;
}
let targetCmd = rootCmd;
for (const name of commandPath) {
targetCmd = targetCmd?.commands.find((c) => c.name() === name);
}
if (!targetCmd) {
throw new Error(
`Could not find package command '${commandPath.join(" ")}'`
);
}
const cmd = targetCmd;
const expectedScript = `backstage-cli ${commandPath.join(" ")}`;
return (scriptStr) => {
if (!scriptStr || !scriptStr.startsWith(expectedScript)) {
return void 0;
}
const argsStr = scriptStr.slice(expectedScript.length).trim();
const currentOpts = cmd._optionValues;
const currentStore = cmd._storeOptionsAsProperties;
const result = {};
cmd._storeOptionsAsProperties = false;
cmd._optionValues = result;
cmd.parseOptions(argsStr.split(" "));
cmd._storeOptionsAsProperties = currentOpts;
cmd._optionValues = currentStore;
return result;
};
}
exports.createScriptOptionsParser = createScriptOptionsParser;
//# sourceMappingURL=optionsParser.cjs.js.map
;