diff --git a/.changeset/honest-boats-attend.md b/.changeset/honest-boats-attend.md new file mode 100644 index 00000000..77d4c509 --- /dev/null +++ b/.changeset/honest-boats-attend.md @@ -0,0 +1,5 @@ +--- +"varlock": patch +--- + +feat: add `--compact` flag `varlock load`. diff --git a/packages/varlock/src/cli/commands/load.command.ts b/packages/varlock/src/cli/commands/load.command.ts index cb088d1a..b8afefcd 100644 --- a/packages/varlock/src/cli/commands/load.command.ts +++ b/packages/varlock/src/cli/commands/load.command.ts @@ -19,6 +19,10 @@ export const commandSpec = define({ description: 'Format of output', default: 'pretty', }, + compact: { + type: 'boolean', + description: 'Use compact format (for json-full: no indentation, for env: skip undefined values)', + }, 'show-all': { type: 'boolean', description: 'When load is failing, show all items rather than only failing items', @@ -32,7 +36,7 @@ export const commandSpec = define({ export const commandFn: TypedGunshiCommandFn = async (ctx) => { - const { format, 'show-all': showAll } = ctx.values; + const { format, compact, 'show-all': showAll } = ctx.values; const envGraph = await loadVarlockEnvGraph({ currentEnvFallback: ctx.values.env, @@ -75,11 +79,19 @@ export const commandFn: TypedGunshiCommandFn = async (ctx) = } else if (format === 'json') { console.log(JSON.stringify(envGraph.getResolvedEnvObject(), null, 2)); } else if (format === 'json-full' || format === 'json-full-compact') { - console.log(JSON.stringify(envGraph.getSerializedGraph(), null, format === 'json-full-compact' ? 0 : 2)); + const indent = format === 'json-full-compact' || compact ? 0 : 2; + console.log(JSON.stringify(envGraph.getSerializedGraph(), null, indent)); } else if (format === 'env') { const resolvedEnv = envGraph.getResolvedEnvObject(); + const skipUndefined = compact === true; + for (const key in resolvedEnv) { const value = resolvedEnv[key]; + + if (value === undefined && skipUndefined) { + continue; + } + let strValue: string; if (value === undefined) { strValue = '';