From cebbf8a27f3c4c0ae34c632dcecd2e354bdb421f Mon Sep 17 00:00:00 2001 From: djamaile Date: Mon, 24 Jul 2023 20:53:02 +0200 Subject: [PATCH 1/3] feat(cli): enable to print the config schema non merged Signed-off-by: djamaile --- .changeset/rare-pens-exist.md | 5 +++++ packages/cli/src/commands/config/schema.ts | 26 +++++++++++++--------- packages/cli/src/commands/index.ts | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .changeset/rare-pens-exist.md diff --git a/.changeset/rare-pens-exist.md b/.changeset/rare-pens-exist.md new file mode 100644 index 0000000000..d5dd1cf5aa --- /dev/null +++ b/.changeset/rare-pens-exist.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Enable to print the config schema non merged with the `non-merged` flag diff --git a/packages/cli/src/commands/config/schema.ts b/packages/cli/src/commands/config/schema.ts index f9e6573be6..3241615986 100644 --- a/packages/cli/src/commands/config/schema.ts +++ b/packages/cli/src/commands/config/schema.ts @@ -28,19 +28,23 @@ export default async (opts: OptionValues) => { mockEnv: true, }); - const merged = mergeConfigSchemas( - (schema.serialize().schemas as JsonObject[]).map( - _ => _.value as JSONSchema, - ), - ); - - merged.title = 'Application Configuration Schema'; - merged.description = - 'This is the schema describing the structure of the app-config.yaml configuration file.'; + let configSchema: JsonObject | JSONSchema; + if (!opts.nonMerged) { + configSchema = mergeConfigSchemas( + (schema.serialize().schemas as JsonObject[]).map( + _ => _.value as JSONSchema, + ), + ); + configSchema.title = 'Application Configuration Schema'; + configSchema.description = + 'This is the schema describing the structure of the app-config.yaml configuration file.'; + } else { + configSchema = schema.serialize(); + } if (opts.format === 'json') { - process.stdout.write(`${JSON.stringify(merged, null, 2)}\n`); + process.stdout.write(`${JSON.stringify(configSchema, null, 2)}\n`); } else { - process.stdout.write(`${stringifyYaml(merged)}\n`); + process.stdout.write(`${stringifyYaml(configSchema)}\n`); } }; diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 1fa7fe2964..b56914dfdc 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -365,6 +365,7 @@ export function registerCommands(program: Command) { '--format ', 'Format to print the schema in, either json or yaml [yaml]', ) + .option('--non-merged', 'Enable to print the config schema non merged') .description('Print configuration schema') .action(lazy(() => import('./config/schema').then(m => m.default))); From 8ebe96fecee0eb7c896baa20968ad7a6ffd61446 Mon Sep 17 00:00:00 2001 From: djamaile Date: Mon, 24 Jul 2023 21:33:04 +0200 Subject: [PATCH 2/3] refactor: add --merged and --no-merged flag Signed-off-by: djamaile --- .changeset/rare-pens-exist.md | 2 +- packages/cli/cli-report.md | 2 ++ packages/cli/src/commands/config/schema.ts | 2 +- packages/cli/src/commands/index.ts | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.changeset/rare-pens-exist.md b/.changeset/rare-pens-exist.md index d5dd1cf5aa..dd48d1ab50 100644 --- a/.changeset/rare-pens-exist.md +++ b/.changeset/rare-pens-exist.md @@ -2,4 +2,4 @@ '@backstage/cli': patch --- -Enable to print the config schema non merged with the `non-merged` flag +Enable to print the config schema non merged with the `--no-merged` flag diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index 4cf5c6329c..1ce2963491 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -97,6 +97,8 @@ Usage: backstage-cli config:schema [options] Options: --package --format + --merged + --no-merged -h, --help ``` diff --git a/packages/cli/src/commands/config/schema.ts b/packages/cli/src/commands/config/schema.ts index 3241615986..28c7c9327a 100644 --- a/packages/cli/src/commands/config/schema.ts +++ b/packages/cli/src/commands/config/schema.ts @@ -29,7 +29,7 @@ export default async (opts: OptionValues) => { }); let configSchema: JsonObject | JSONSchema; - if (!opts.nonMerged) { + if (opts.merged) { configSchema = mergeConfigSchemas( (schema.serialize().schemas as JsonObject[]).map( _ => _.value as JSONSchema, diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index b56914dfdc..1839dea8a5 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -365,7 +365,8 @@ export function registerCommands(program: Command) { '--format ', 'Format to print the schema in, either json or yaml [yaml]', ) - .option('--non-merged', 'Enable to print the config schema non merged') + .option('--merged', 'Print the config schemas merged', true) + .option('--no-merged', 'Print the config schemas not merged') .description('Print configuration schema') .action(lazy(() => import('./config/schema').then(m => m.default))); From 37e07cbe9daeed875ccaf333fc242738a864c65c Mon Sep 17 00:00:00 2001 From: djamaile Date: Tue, 25 Jul 2023 10:16:13 +0200 Subject: [PATCH 3/3] refactor: change flags from --merged to --merge Signed-off-by: djamaile --- .changeset/rare-pens-exist.md | 2 +- packages/cli/cli-report.md | 4 ++-- packages/cli/src/commands/config/schema.ts | 2 +- packages/cli/src/commands/index.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.changeset/rare-pens-exist.md b/.changeset/rare-pens-exist.md index dd48d1ab50..7363f5033a 100644 --- a/.changeset/rare-pens-exist.md +++ b/.changeset/rare-pens-exist.md @@ -2,4 +2,4 @@ '@backstage/cli': patch --- -Enable to print the config schema non merged with the `--no-merged` flag +Enable to print the config schema not merged with the `--no-merge` flag diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index 1ce2963491..e20634df4e 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -97,8 +97,8 @@ Usage: backstage-cli config:schema [options] Options: --package --format - --merged - --no-merged + --merge + --no-merge -h, --help ``` diff --git a/packages/cli/src/commands/config/schema.ts b/packages/cli/src/commands/config/schema.ts index 28c7c9327a..08bc46d1cc 100644 --- a/packages/cli/src/commands/config/schema.ts +++ b/packages/cli/src/commands/config/schema.ts @@ -29,7 +29,7 @@ export default async (opts: OptionValues) => { }); let configSchema: JsonObject | JSONSchema; - if (opts.merged) { + if (opts.merge) { configSchema = mergeConfigSchemas( (schema.serialize().schemas as JsonObject[]).map( _ => _.value as JSONSchema, diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 1839dea8a5..a7f65588a5 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -365,8 +365,8 @@ export function registerCommands(program: Command) { '--format ', 'Format to print the schema in, either json or yaml [yaml]', ) - .option('--merged', 'Print the config schemas merged', true) - .option('--no-merged', 'Print the config schemas not merged') + .option('--merge', 'Print the config schemas merged', true) + .option('--no-merge', 'Print the config schemas not merged') .description('Print configuration schema') .action(lazy(() => import('./config/schema').then(m => m.default)));