Skip to content

Commit fdd62a7

Browse files
committed
feat: Improved plan printing more
1 parent 4f81fa4 commit fdd62a7

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"deploy": "npm run pkg && npm run notarize && npm run upload",
146146
"prepublishOnly": "npm run build"
147147
},
148-
"version": "1.2.0-beta.1",
148+
"version": "1.2.0-beta.2",
149149
"bugs": "https://github.com/codifycli/codify/issues",
150150
"keywords": [
151151
"oclif",

src/ui/plan-pretty-printer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,29 +251,33 @@ function formatObjectDiff(name: string, previousValue: Record<string, unknown>,
251251
}
252252
}
253253

254+
// Layout: every line uses [3 spaces][sym][2 spaces (JSON indent)][content]
255+
// sym col=3, content col=6 — matches the outer block's "~ content" (sym=0, content=5) + 1 level deeper
254256
const resultLines: string[] = [`${chalk.yellow('~')} "${name}": {`];
255257
let lastIncluded = -1;
256258

257259
for (let i = 0; i < entries.length; i++) {
258260
if (!includedIndices.has(i)) continue;
259261
if (lastIncluded !== -1 && i > lastIncluded + 1) {
260-
resultLines.push(' ...');
262+
resultLines.push(' ...');
261263
}
262264
lastIncluded = i;
263265
const { op, key, prev, next } = entries[i];
264266

267+
// All inner lines: sym at col 4, content at col 7 (2-space JSON indent relative to { at col 5).
268+
// Noop uses a space for sym so content stays at col 7.
265269
if (op === 'noop') {
266270
resultLines.push(` "${key}": ${formatValue(next)},`);
267271
} else if (op === 'add') {
268-
resultLines.push(` ${chalk.green('+')} ${chalk.green(`"${key}": ${formatValue(next)},`)}`);
272+
resultLines.push(` ${chalk.green('+')} ${chalk.green(`"${key}": ${formatValue(next)},`)}`);
269273
} else if (op === 'remove') {
270-
resultLines.push(` ${chalk.red('-')} ${chalk.red(`"${key}": ${formatValue(prev)},`)}`);
274+
resultLines.push(` ${chalk.red('-')} ${chalk.red(`"${key}": ${formatValue(prev)},`)}`);
271275
} else {
272-
resultLines.push(` ${chalk.yellow('~')} "${key}": ${formatValue(prev)} -> ${formatValue(next)},`);
276+
resultLines.push(` ${chalk.yellow('~')} ${chalk.yellow(`"${key}": ${formatValue(prev)} -> ${formatValue(next)},`)}`);
273277
}
274278
}
275279

276-
resultLines.push(' },');
280+
resultLines.push(' },');
277281
return resultLines.join('\n');
278282
}
279283

test/utils/plan-pretty-printer.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,40 @@ describe('Plan pretty printer', () => {
8787
console.log(prettyFormatResourcePlan(new ResourcePlan(plan)))
8888
})
8989

90+
it('Can diff nested objects with adds, removes, and modifies', () => {
91+
const plan: PlanResponseData = {
92+
planId: '18d9dbbc-9dd1-4581-9a6a-db146d44c829',
93+
resourceType: 'macos-settings',
94+
operation: ResourceOperation.MODIFY,
95+
isStateful: false,
96+
parameters: [
97+
{
98+
name: 'mouse',
99+
previousValue: { naturalScrolling: true, speed: 1.5 },
100+
newValue: { naturalScrolling: false, speed: 1.5 },
101+
operation: ParameterOperation.MODIFY,
102+
isSensitive: false,
103+
},
104+
{
105+
name: 'keyboard',
106+
previousValue: { pressAndHold: false, fnKeysAsStandardKeys: true },
107+
newValue: { keyRepeat: 6, initialKeyRepeat: 68, pressAndHold: true, fnKeysAsStandardKeys: true },
108+
operation: ParameterOperation.MODIFY,
109+
isSensitive: false,
110+
},
111+
{
112+
name: 'dock',
113+
previousValue: { position: 'bottom', autohide: true, minimizeEffect: 'scale' },
114+
newValue: { position: 'bottom', autohide: false, showRecents: true, minimizeEffect: 'genie' },
115+
operation: ParameterOperation.MODIFY,
116+
isSensitive: false,
117+
},
118+
]
119+
}
120+
121+
console.log(prettyFormatResourcePlan(new ResourcePlan(plan)))
122+
})
123+
90124
it('Can print modify and re-create plans', () => {
91125
const plan: PlanResponseData = {
92126
planId: 'id',

0 commit comments

Comments
 (0)