cli: add info to alpha context
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -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`
|
||||
|
||||
@@ -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' },
|
||||
@@ -65,6 +64,7 @@ export default createCliPlugin({
|
||||
format: { type: 'string' },
|
||||
config: { type: 'string', array: true },
|
||||
})
|
||||
.usage(`$0 ${info.usageWithoutProgram}`, info.description)
|
||||
.help()
|
||||
.parse(args);
|
||||
const m =
|
||||
|
||||
@@ -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,11 @@ export class CliInitializer {
|
||||
}
|
||||
await node.command.execute({
|
||||
args: [...positionalArgs, ...args.unknown],
|
||||
info: {
|
||||
usage: [programName, ...node.command.path].join(' '),
|
||||
usageWithoutProgram: node.command.path.join(' '),
|
||||
description: node.command.description,
|
||||
},
|
||||
});
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
|
||||
@@ -19,7 +19,23 @@ 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 usage string of the current command, without the program name, for example: "repo test"
|
||||
*/
|
||||
usageWithoutProgram: string;
|
||||
/**
|
||||
* The description provided for the command
|
||||
*/
|
||||
description: string;
|
||||
};
|
||||
}) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface CliFeature {
|
||||
|
||||
Reference in New Issue
Block a user