Fix CLI report generation and --help handling for loader-based commands

Add cleye-based --help handling to all commands using the loader pattern.
Update the CLI report parser to support cleye's USAGE: and FLAGS: sections.
Revert accidental backstage.role addition to eslint-plugin.

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-26 20:31:55 +01:00
parent 0d2d0f2e07
commit d5779e525c
12 changed files with 106 additions and 76 deletions
@@ -14,11 +14,14 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import fs from 'fs-extra';
import { targetPaths } from '@backstage/cli-common';
import type { CommandContext } from '../../../../wiring/types';
export default async function clean() {
export default async ({ args, info }: CommandContext) => {
cli({ help: info }, undefined, args);
await fs.remove(targetPaths.resolve('dist'));
await fs.remove(targetPaths.resolve('dist-types'));
await fs.remove(targetPaths.resolve('coverage'));
}
};
@@ -14,13 +14,15 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph } from '@backstage/cli-node';
import { run, targetPaths } from '@backstage/cli-common';
import type { CommandContext } from '../../../../wiring/types';
export default async function command(): Promise<void> {
export default async ({ args, info }: CommandContext) => {
cli({ help: info }, undefined, args);
const packages = await PackageGraph.listTargetPackages();
await fs.remove(targetPaths.resolveRoot('dist'));
@@ -48,4 +50,4 @@ export default async function command(): Promise<void> {
}
}),
);
}
};
+5 -2
View File
@@ -14,6 +14,7 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import { Command, Option } from 'commander';
import { createCliPlugin } from '../../wiring/factory';
import { lazy } from '../../wiring/lazy';
@@ -214,7 +215,8 @@ export const buildPlugin = createCliPlugin({
reg.addCommand({
path: ['package', 'prepack'],
description: 'Prepares a package for packaging before publishing',
execute: async () => {
execute: async ({ args, info }) => {
cli({ help: info }, undefined, args);
const { pre } = await import('./commands/package/pack');
await pre();
},
@@ -223,7 +225,8 @@ export const buildPlugin = createCliPlugin({
reg.addCommand({
path: ['package', 'postpack'],
description: 'Restores the changes made by the prepack command',
execute: async () => {
execute: async ({ args, info }) => {
cli({ help: info }, undefined, args);
const { post } = await import('./commands/package/pack');
await post();
},
@@ -14,8 +14,12 @@
* limitations under the License.
*/
export default async function command() {
import { cli } from 'cleye';
import type { CommandContext } from '../../../wiring/types';
export default async ({ args, info }: CommandContext) => {
cli({ help: info }, undefined, args);
throw new Error(
'The `migrate package-exports` command has been removed, use `repo fix` instead.',
);
}
};
@@ -14,14 +14,17 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph } from '@backstage/cli-node';
import { runOutput } from '@backstage/cli-common';
import type { CommandContext } from '../../../wiring/types';
const PREFIX = `module.exports = require('@backstage/cli/config/eslint-factory')`;
export default async function command() {
export default async ({ args, info }: CommandContext) => {
cli({ help: info }, undefined, args);
const packages = await PackageGraph.listTargetPackages();
const oldConfigs = [
@@ -86,4 +89,4 @@ export default async function command() {
if (hasPrettier) {
await runOutput(['prettier', '--write', ...configPaths]);
}
}
};
@@ -14,13 +14,16 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'node:path';
import { getPackages } from '@manypkg/get-packages';
import { PackageRoles } from '@backstage/cli-node';
import { targetPaths } from '@backstage/cli-common';
import type { CommandContext } from '../../../wiring/types';
export default async () => {
export default async ({ args, info }: CommandContext) => {
cli({ help: info }, undefined, args);
const { packages } = await getPackages(targetPaths.dir);
await Promise.all(
@@ -14,15 +14,18 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph, PackageRoles, PackageRole } from '@backstage/cli-node';
import type { CommandContext } from '../../../wiring/types';
const configArgPattern = /--config[=\s][^\s$]+/;
const noStartRoles: PackageRole[] = ['cli', 'common-library'];
export default async function command() {
export default async ({ args, info }: CommandContext) => {
cli({ help: info }, undefined, args);
const packages = await PackageGraph.listTargetPackages();
await Promise.all(
@@ -104,4 +107,4 @@ export default async function command() {
}
}),
);
}
};
@@ -14,14 +14,17 @@
* limitations under the License.
*/
import { cli } from 'cleye';
import fs from 'fs-extra';
import { resolve as resolvePath } from 'node:path';
import { PackageGraph, PackageRoles } from '@backstage/cli-node';
import type { CommandContext } from '../../../wiring/types';
const REACT_ROUTER_DEPS = ['react-router', 'react-router-dom'];
const REACT_ROUTER_RANGE = '6.0.0-beta.0 || ^6.3.0';
export default async function command() {
export default async ({ args, info }: CommandContext) => {
cli({ help: info }, undefined, args);
const packages = await PackageGraph.listTargetPackages();
await Promise.all(
@@ -56,4 +59,4 @@ export default async function command() {
}
}),
);
}
};