Skip to content

Review init code, make sure we always prompt if data needs to be overwritten #48

Description

@richardpark-msft

Summary

Review init code, make sure we always prompt if data needs to be overwritten.

This isn't asserting that there is a bug in init, but more just making sure we review any cases that write out files to ensure that we don't ever clobber user data.

Architecture Context

Create internal/scaffold/writer.go with a FileWriter service that encapsulates the create-if-missing + skip-if-exists pattern. It replaces the inline file-write loop in cmd/waza/cmd_init.go:518-541. The FileWriter accepts a list of files to write, checks existence, creates missing files, and returns an inventory of outcomes. The inventory is always printed - not gated behind --verbose.

Today both cmd_init.go and cmd_new.go have independent file-write loops with subtly different skip logic. A shared writer ensures consistent behavior and makes the inventory output testable.

Core rule: waza init only creates files that don't exist. Existing files are never overwritten or merged. Load() already fills in runtime defaults for missing config sections.

Architecture doc: docs/init-config-consolidation/architecture.md

Acceptance Criteria

  • internal/scaffold/writer.go exists with a FileWriter type
  • FileWriter returns a structured inventory: each entry has path + outcome (created vs skipped)
  • cmd/waza/cmd_init.go uses FileWriter instead of its inline write loop
  • Running waza init in an empty directory creates all files and prints created marker for each
  • Running waza init again in the same directory skips all files and prints exists marker for each
  • Inventory is always visible (not gated behind --verbose)
  • internal/scaffold/writer_test.go covers: create-if-missing, skip-if-exists, inventory output, directory creation
  • Existing TestInitCommand_NeverOverwrites and TestInitCommand_Idempotent still pass
  • go test ./... passes; golangci-lint run passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic:go-cliE1: Go CLI FoundationgoPull requests that update go codepriority:p1This sprint

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions