Merge pull request #29744 from backstage/rugvip/cli-info

cli: add info to alpha context
This commit is contained in:
Patrik Oldsberg
2025-04-28 22:12:32 +02:00
committed by GitHub
5 changed files with 40 additions and 18 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Added `info` object to the context of the alpha CLI.
@@ -56,12 +56,11 @@ Commands:
### `backstage-cli-alpha config docs`
```
Usage: <none>
Usage: backstage-cli config docs [options]
Options:
--help
--package
--version
--package <name>
-h, --help
```
### `backstage-cli-alpha config schema`
+12 -12
View File
@@ -40,22 +40,21 @@ export default createCliPlugin({
reg.addCommand({
path: ['config', 'docs'],
description: 'Browse the configuration reference documentation',
execute: async ({ args }) => {
const argv = await yargs
.options({
package: { type: 'string' },
})
.help()
.parse(args);
const m =
(await require('./commands/docs')) as typeof import('./commands/docs');
await m.default(argv);
execute: async ({ args, info }) => {
await new Command(info.usage)
.option(
'--package <name>',
'Only include the schema that applies to the given package',
)
.description(info.description)
.action(lazy(() => import('./commands/docs'), 'default'))
.parseAsync(args, { from: 'user' });
},
});
reg.addCommand({
path: ['config:print'],
description: 'Print the app configuration for the current package',
execute: async ({ args }) => {
execute: async ({ args, info }) => {
const argv = await yargs
.options({
package: { type: 'string' },
@@ -63,8 +62,9 @@ export default createCliPlugin({
frontend: { type: 'boolean' },
'with-secrets': { type: 'boolean' },
format: { type: 'string' },
config: { type: 'string', array: true },
config: { type: 'string', array: true, default: [] },
})
.usage('$0', info.description)
.help()
.parse(args);
const m =
+7 -1
View File
@@ -62,9 +62,11 @@ export class CliInitializer {
async run() {
await this.#doInit();
const programName = 'backstage-cli';
const program = new Command();
program
.name('backstage-cli')
.name(programName)
.version(version)
.allowUnknownOption(true)
.allowExcessArguments(true);
@@ -117,6 +119,10 @@ export class CliInitializer {
}
await node.command.execute({
args: [...positionalArgs, ...args.unknown],
info: {
usage: [programName, ...node.command.path].join(' '),
description: node.command.description,
},
});
process.exit(0);
} catch (error) {
+13 -1
View File
@@ -19,7 +19,19 @@ export interface BackstageCommand {
path: string[];
description: string;
deprecated?: boolean;
execute: (options: { args: string[] }) => Promise<void>;
execute: (context: {
args: string[];
info: {
/**
* The usage string of the current command, for example: "backstage-cli repo test"
*/
usage: string;
/**
* The description provided for the command
*/
description: string;
};
}) => Promise<void>;
}
export interface CliFeature {