Title
worklog init: starter config writer
Summary
Implement worklog init: write the commented starter config
(config.Starter(), issue 05) to the default (or --config) path with
safe-write semantics, refusing to overwrite without --force.
Context
This is the second and last legitimate write path (invariant I3). It reuses
the atomic-write mechanics but targets the config location and must create
~/.config/worklog/ correctly on first run.
Scope
internal/cli/init.go (replace stub) + tests.
Detailed Requirements
- Target:
--config value if given, else config.DefaultPath().
- Behavior: existing file + no
--force → message
config already exists: <path> (use --force to overwrite) to stderr,
exit 1. Otherwise: create parent dirs 0700, atomic temp+rename write,
file mode 0600 (config may later hold llm.api_key), then print
wrote <path> to stderr and, to stdout, the 3-line quickstart:
Edit the config, then run: / worklog doctor / worklog daily.
- Symlink final component → refuse (same rule as 22; reuse
output-package internals via a small exported helper
output.WriteFileSafe(path string, content []byte, force bool) error
— refactor 22's core into this helper in THIS issue, keeping 22's tests
green).
- The written file must round-trip:
config.Load(path) → zero warnings,
zero validation errors. This holds because config.Starter() (issue 05)
ships [llm] enabled = false with the guidance comment — identical to
the built-in default (DESIGN §5), so no starter-vs-default divergence
exists.
init ignores --date/--lang etc. (not registered on its FlagSet, 07
already scoped flags).
Acceptance Criteria
Validation
go test -race -cover ./internal/cli/ ./internal/output/ ./internal/config/
in PR (three packages touched).
Dependencies
05, 07, 22 (hard dependency: this issue refactors 22's write core into the
shared output.WriteFileSafe helper).
Non-goals
Interactive prompts/wizards, config migration between versions (post-v1),
editing existing configs.
Design References
docs/DESIGN.md §5, §10, §1.2 (I3)
Source of truth: docs/issues/27-cmd-init.md (PR #1, branch docs/v1-design). If this issue and the repo docs disagree, the docs win. Execution order and dependencies: docs/ISSUE_PLAN.md (this is issue 27 of 33).
Title
worklog init: starter config writerSummary
Implement
worklog init: write the commented starter config(
config.Starter(), issue 05) to the default (or--config) path withsafe-write semantics, refusing to overwrite without
--force.Context
This is the second and last legitimate write path (invariant I3). It reuses
the atomic-write mechanics but targets the config location and must create
~/.config/worklog/correctly on first run.Scope
internal/cli/init.go(replace stub) + tests.Detailed Requirements
--configvalue if given, elseconfig.DefaultPath().--force→ messageconfig already exists: <path> (use --force to overwrite)to stderr,exit 1. Otherwise: create parent dirs 0700, atomic temp+rename write,
file mode 0600 (config may later hold
llm.api_key), then printwrote <path>to stderr and, to stdout, the 3-line quickstart:Edit the config, then run:/worklog doctor/worklog daily.output-package internals via a small exported helperoutput.WriteFileSafe(path string, content []byte, force bool) error— refactor 22's core into this helper in THIS issue, keeping 22's tests
green).
config.Load(path)→ zero warnings,zero validation errors. This holds because
config.Starter()(issue 05)ships
[llm] enabled = falsewith the guidance comment — identical tothe built-in default (DESIGN §5), so no starter-vs-default divergence
exists.
initignores--date/--langetc. (not registered on its FlagSet, 07already scoped flags).
Acceptance Criteria
Starter()bytes, 0600/0700modes, correct stdout/stderr split, exit 0.
--force→ exit 1, file untouched(hash-asserted); with
--force→ replaced atomically.Loadon the written file → no warnings, no validationerrors.
XDG_CONFIG_HOMErespected when set (test both with and without).WriteFileSaferefactor.Validation
go test -race -cover ./internal/cli/ ./internal/output/ ./internal/config/in PR (three packages touched).
Dependencies
05, 07, 22 (hard dependency: this issue refactors 22's write core into the
shared
output.WriteFileSafehelper).Non-goals
Interactive prompts/wizards, config migration between versions (post-v1),
editing existing configs.
Design References
docs/DESIGN.md§5, §10, §1.2 (I3)Source of truth:
docs/issues/27-cmd-init.md(PR #1, branchdocs/v1-design). If this issue and the repo docs disagree, the docs win. Execution order and dependencies:docs/ISSUE_PLAN.md(this is issue 27 of 33).