From d0fc357c37f1eeb56ab16500b7e27a85caea4611 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 3 Mar 2025 20:12:55 +0100 Subject: [PATCH] cli: migrate info command to module Signed-off-by: Patrik Oldsberg --- .changeset/sweet-zoos-beam.md | 5 +++ packages/cli/cli-report.md | 2 +- packages/cli/src/alpha.ts | 1 + packages/cli/src/commands/index.ts | 7 ++-- packages/cli/src/modules/info/alpha.ts | 33 +++++++++++++++++++ .../src/{ => modules/info}/commands/info.ts | 10 +++--- packages/cli/src/modules/info/index.ts | 25 ++++++++++++++ 7 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 .changeset/sweet-zoos-beam.md create mode 100644 packages/cli/src/modules/info/alpha.ts rename packages/cli/src/{ => modules/info}/commands/info.ts (89%) create mode 100644 packages/cli/src/modules/info/index.ts diff --git a/.changeset/sweet-zoos-beam.md b/.changeset/sweet-zoos-beam.md new file mode 100644 index 0000000000..e13ebcd30d --- /dev/null +++ b/.changeset/sweet-zoos-beam.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Internal update to move `info` commands to a separate module. diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index 02051b69f7..5d043158e6 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -23,8 +23,8 @@ Commands: versions:migrate [options] migrate [command] build-workspace [options] [packages...] - create-github-app info + create-github-app help [command] ``` diff --git a/packages/cli/src/alpha.ts b/packages/cli/src/alpha.ts index 85a8763974..e46f9d9e9f 100644 --- a/packages/cli/src/alpha.ts +++ b/packages/cli/src/alpha.ts @@ -24,6 +24,7 @@ import chalk from 'chalk'; ), ); const initializer = new CliInitializer(); + initializer.add(import('./modules/info/alpha')); initializer.add(import('./modules/config/alpha')); initializer.add(import('./modules/build/alpha')); initializer.add(import('./modules/migrate/alpha')); diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index ee2af9541c..8aa3928cfd 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -25,6 +25,7 @@ import { registerRepoCommands as registerRepoBuildCommands, registerCommands as registerBuildCommands, } from '../modules/build'; +import { registerCommands as registerInfoCommands } from '../modules/info'; import { registerCommands as registerMigrateCommand } from '../modules/migrate'; export function registerRepoCommand(program: Command) { @@ -214,17 +215,13 @@ export function registerCommands(program: Command) { registerScriptCommand(program); registerMigrateCommand(program); registerBuildCommands(program); + registerInfoCommands(program); program .command('create-github-app ') .description('Create new GitHub App in your organization.') .action(lazy(() => import('./create-github-app'), 'default')); - program - .command('info') - .description('Show helpful information for debugging and reporting bugs') - .action(lazy(() => import('./info'), 'default')); - // Notifications for removed commands program .command('create') diff --git a/packages/cli/src/modules/info/alpha.ts b/packages/cli/src/modules/info/alpha.ts new file mode 100644 index 0000000000..1e6f761f83 --- /dev/null +++ b/packages/cli/src/modules/info/alpha.ts @@ -0,0 +1,33 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import yargs from 'yargs'; +import { createCliPlugin } from '../../wiring/factory'; + +export default createCliPlugin({ + pluginId: 'info', + init: async reg => { + reg.addCommand({ + path: ['info'], + description: 'Show helpful information for debugging and reporting bugs', + execute: async ({ args }) => { + yargs().parse(args); + const { default: command } = + require('./commands/info') as typeof import('./commands/info'); + await command(); + }, + }); + }, +}); diff --git a/packages/cli/src/commands/info.ts b/packages/cli/src/modules/info/commands/info.ts similarity index 89% rename from packages/cli/src/commands/info.ts rename to packages/cli/src/modules/info/commands/info.ts index f3740de1a9..416c995541 100644 --- a/packages/cli/src/commands/info.ts +++ b/packages/cli/src/modules/info/commands/info.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 The Backstage Authors + * Copyright 2025 The Backstage Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,11 +14,11 @@ * limitations under the License. */ -import { version as cliVersion } from '../../package.json'; +import { version as cliVersion } from '../../../../package.json'; import os from 'os'; -import { runPlain } from '../lib/run'; -import { paths } from '../lib/paths'; -import { Lockfile } from '../lib/versioning'; +import { runPlain } from '../../../lib/run'; +import { paths } from '../../../lib/paths'; +import { Lockfile } from '../../../lib/versioning'; import fs from 'fs-extra'; export default async () => { diff --git a/packages/cli/src/modules/info/index.ts b/packages/cli/src/modules/info/index.ts new file mode 100644 index 0000000000..af43af652c --- /dev/null +++ b/packages/cli/src/modules/info/index.ts @@ -0,0 +1,25 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { lazy } from '../../lib/lazy'; +import { Command } from 'commander'; + +export function registerCommands(program: Command) { + program + .command('info') + .description('Show helpful information for debugging and reporting bugs') + .action(lazy(() => import('./commands/info'), 'default')); +}