Skip to content

Commit 8db610f

Browse files
committed
feat!: remove JSON output format from diff command
BREAKING CHANGE: The --format flag has been removed from the diff command. JSON output is no longer supported. The diff command now only outputs human-readable text format. This change simplifies the diff module by removing JSON marshaling logic, format validation, and output routing complexity. Users who previously used --format=json will need to parse the text output or use alternative tools for structured data extraction. Changes: - Remove --format flag from diff command - Remove JSON output capability from internal/diff module - Remove Format field from diff.Options struct - Remove toJSON() method and related JSON formatting code - Rename diffWithConfig to diffSingleStack for consistency - Update all tests to reflect simplified Options struct - Update architecture documentation to reflect text-only output This reduces codebase complexity by ~150 lines while maintaining all core diff analysis capabilities with rich text formatting.
1 parent b97d6ae commit 8db610f

File tree

9 files changed

+98
-426
lines changed

9 files changed

+98
-426
lines changed

cmd/diff.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717
diffTemplateOnly bool
1818
diffParametersOnly bool
1919
diffTagsOnly bool
20-
diffFormat string
20+
2121
// differ can be injected for testing
2222
differ diff.Differ
2323
)
@@ -39,20 +39,14 @@ the current configuration. It compares:
3939
Examples:
4040
stackaroo diff dev vpc # Show all changes
4141
stackaroo diff prod vpc --template # Template diff only
42-
stackaroo diff dev vpc --parameters # Parameter diff only
43-
stackaroo diff dev vpc --format json # JSON output`,
42+
stackaroo diff dev vpc --parameters # Parameter diff only`,
4443
Args: cobra.ExactArgs(2),
4544
RunE: func(cmd *cobra.Command, args []string) error {
4645
contextName := args[0]
4746
stackName := args[1]
4847
ctx := context.Background()
4948

50-
// Validate format option
51-
if diffFormat != "text" && diffFormat != "json" {
52-
return fmt.Errorf("--format must be 'text' or 'json'")
53-
}
54-
55-
return diffWithConfig(ctx, stackName, contextName)
49+
return diffSingleStack(ctx, stackName, contextName)
5650
},
5751
}
5852

@@ -79,8 +73,8 @@ func SetDiffer(d diff.Differ) {
7973
differ = d
8074
}
8175

82-
// diffWithConfig handles diff using configuration file
83-
func diffWithConfig(ctx context.Context, stackName, contextName string) error {
76+
// diffSingleStack handles diff using configuration file
77+
func diffSingleStack(ctx context.Context, stackName, contextName string) error {
8478
_, resolver := createResolver()
8579

8680
// Resolve the target stack
@@ -94,7 +88,6 @@ func diffWithConfig(ctx context.Context, stackName, contextName string) error {
9488
TemplateOnly: diffTemplateOnly,
9589
ParametersOnly: diffParametersOnly,
9690
TagsOnly: diffTagsOnly,
97-
Format: diffFormat,
9891
}
9992

10093
// Get or create differ
@@ -128,6 +121,4 @@ func init() {
128121
diffCmd.Flags().BoolVar(&diffParametersOnly, "parameters", false, "show only parameter differences")
129122
diffCmd.Flags().BoolVar(&diffTagsOnly, "tags", false, "show only tag differences")
130123

131-
// Output format flag
132-
diffCmd.Flags().StringVar(&diffFormat, "format", "text", "output format: text, json")
133124
}

cmd/diff_test.go

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ func TestDiffCmd_Structure(t *testing.T) {
3838
require.NotNil(t, tagsFlag)
3939
assert.Equal(t, "false", tagsFlag.DefValue)
4040

41-
formatFlag := flags.Lookup("format")
42-
require.NotNil(t, formatFlag)
43-
assert.Equal(t, "text", formatFlag.DefValue)
4441
}
4542

4643
func TestDiffCmd_RequiredArgs(t *testing.T) {
@@ -67,21 +64,6 @@ func TestDiffCmd_MissingContext(t *testing.T) {
6764
t.Skip("Context is now a positional argument, validated by Args")
6865
}
6966

70-
func TestDiffCmd_InvalidFormat(t *testing.T) {
71-
// Setup
72-
diffFormat = "invalid"
73-
74-
// Execute
75-
err := diffCmd.RunE(diffCmd, []string{"dev", "test-stack"})
76-
77-
// Verify
78-
assert.Error(t, err)
79-
assert.Contains(t, err.Error(), "--format must be 'text' or 'json'")
80-
81-
// Cleanup
82-
diffFormat = "text"
83-
}
84-
8567
func TestDiffWithConfig_Success_NoChanges(t *testing.T) {
8668
// This test verifies the command logic when differ returns no changes
8769
// We test the business logic without external dependencies
@@ -105,7 +87,7 @@ func TestDiffWithConfig_Success_NoChanges(t *testing.T) {
10587
StackName: "test-stack",
10688
Context: "dev",
10789
StackExists: true,
108-
Options: diff.Options{Format: "text"},
90+
Options: diff.Options{},
10991
}
11092

11193
// Setup expectations - differ should be called with resolved stack
@@ -116,7 +98,7 @@ func TestDiffWithConfig_Success_NoChanges(t *testing.T) {
11698
// Execute with mock resolver - this tests the core logic without file dependencies
11799
// For this unit test, we'll test the differ interaction directly
118100
ctx := context.Background()
119-
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{Format: "text"})
101+
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{})
120102

121103
// Verify
122104
assert.NoError(t, err)
@@ -148,7 +130,7 @@ func TestDiffWithConfig_Success_WithChanges(t *testing.T) {
148130
Context: "dev",
149131
StackExists: true,
150132
ParameterDiffs: []diff.ParameterDiff{{Key: "Param1", CurrentValue: "oldvalue", ProposedValue: "newvalue", ChangeType: diff.ChangeTypeModify}},
151-
Options: diff.Options{Format: "text"},
133+
Options: diff.Options{},
152134
}
153135

154136
// Setup expectations
@@ -158,7 +140,7 @@ func TestDiffWithConfig_Success_WithChanges(t *testing.T) {
158140

159141
// Execute with mock data
160142
ctx := context.Background()
161-
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{Format: "text"})
143+
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{})
162144

163145
// Verify
164146
assert.NoError(t, err)
@@ -195,7 +177,7 @@ func TestDiffWithConfig_NewStack(t *testing.T) {
195177
TemplateChange: &diff.TemplateChange{
196178
HasChanges: true,
197179
},
198-
Options: diff.Options{Format: "text"},
180+
Options: diff.Options{},
199181
}
200182

201183
// Setup expectations
@@ -205,7 +187,7 @@ func TestDiffWithConfig_NewStack(t *testing.T) {
205187

206188
// Execute with mock data
207189
ctx := context.Background()
208-
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{Format: "text"})
190+
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{})
209191

210192
// Verify
211193
assert.NoError(t, err)
@@ -240,7 +222,7 @@ func TestDiffWithConfig_DifferError(t *testing.T) {
240222

241223
// Execute with mock data
242224
ctx := context.Background()
243-
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{Format: "text"})
225+
result, err := mockDiffer.DiffStack(ctx, testStack, diff.Options{})
244226

245227
// Verify
246228
assert.Error(t, err)
@@ -257,59 +239,50 @@ func TestDiffWithConfig_OptionsMapping(t *testing.T) {
257239
templateOnly bool
258240
parametersOnly bool
259241
tagsOnly bool
260-
format string
261242
expectedOptions diff.Options
262243
}{
263244
{
264245
name: "default options",
265246
templateOnly: false,
266247
parametersOnly: false,
267248
tagsOnly: false,
268-
format: "text",
269249
expectedOptions: diff.Options{
270250
TemplateOnly: false,
271251
ParametersOnly: false,
272252
TagsOnly: false,
273-
Format: "text",
274253
},
275254
},
276255
{
277256
name: "template only",
278257
templateOnly: true,
279258
parametersOnly: false,
280259
tagsOnly: false,
281-
format: "json",
282260
expectedOptions: diff.Options{
283261
TemplateOnly: true,
284262
ParametersOnly: false,
285263
TagsOnly: false,
286-
Format: "json",
287264
},
288265
},
289266
{
290267
name: "parameters only",
291268
templateOnly: false,
292269
parametersOnly: true,
293270
tagsOnly: false,
294-
format: "text",
295271
expectedOptions: diff.Options{
296272
TemplateOnly: false,
297273
ParametersOnly: true,
298274
TagsOnly: false,
299-
Format: "text",
300275
},
301276
},
302277
{
303278
name: "tags only",
304279
templateOnly: false,
305280
parametersOnly: false,
306281
tagsOnly: true,
307-
format: "json",
308282
expectedOptions: diff.Options{
309283
TemplateOnly: false,
310284
ParametersOnly: false,
311285
TagsOnly: true,
312-
Format: "json",
313286
},
314287
},
315288
}
@@ -394,7 +367,6 @@ func resetDiffFlags() {
394367
diffTemplateOnly = false
395368
diffParametersOnly = false
396369
diffTagsOnly = false
397-
diffFormat = "text"
398370
}
399371

400372
func TestMain(m *testing.M) {

0 commit comments

Comments
 (0)