Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/honest-boats-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"varlock": patch
---

feat: add `--compact` flag `varlock load`.
16 changes: 14 additions & 2 deletions packages/varlock/src/cli/commands/load.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -32,7 +36,7 @@ export const commandSpec = define({


export const commandFn: TypedGunshiCommandFn<typeof commandSpec> = 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,
Expand Down Expand Up @@ -75,11 +79,19 @@ export const commandFn: TypedGunshiCommandFn<typeof commandSpec> = 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 = '';
Expand Down