Skip to content

feat: Add Init command - create configuration file#10

Merged
thumbrise merged 1 commit into
mainfrom
init-config
May 28, 2026
Merged

feat: Add Init command - create configuration file#10
thumbrise merged 1 commit into
mainfrom
init-config

Conversation

@thumbrise
Copy link
Copy Markdown
Owner

@thumbrise thumbrise commented May 28, 2026

Summary by CodeRabbit

  • New Features
    • Added init CLI command that automatically creates a default configuration file with proper security settings on first run, simplifying validator setup.

Review Change Stack

@thumbrise thumbrise self-assigned this May 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@thumbrise, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 45 minutes and 33 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 16820677-a567-4f0a-9c0f-efc47efae34f

📥 Commits

Reviewing files that changed from the base of the PR and between 572c8a2 and 7195a14.

📒 Files selected for processing (3)
  • cmd/commands/init.go
  • cmd/root.go
  • pkg/validator/config.go
📝 Walkthrough

Walkthrough

This PR introduces a new init CLI command that generates a default configuration file. The ConfigName constant is exported from the config package to support the command, which creates a YAML file with predefined content, enforces 0o600 file permissions, and provides detailed error handling for each stage of file creation.

Changes

Init Command Feature

Layer / File(s) Summary
Config export and init command foundation
pkg/validator/config.go, cmd/commands/init.go
ConfigName is exported so the init command can reference it. Error types (ErrFileExists, ErrCreate, ErrChmod, ErrWrite, ErrStat) and file constants (InitConfigFileName, InitConfigFileMode, InitConfigData) are defined.
Init command file creation logic
cmd/commands/init.go
The init command action checks if the config file exists, creates it with 0o600 permissions, writes the default YAML content, and wraps errors at each stage (stat, create, chmod, write).
CLI command registration
cmd/root.go
The InitCMD is added to the root command's Commands array.

Sequence Diagram

sequenceDiagram
  participant User as User/CLI
  participant InitCMD as InitCMD
  participant OS as Operating System
  User->>InitCMD: Execute init command
  InitCMD->>OS: Stat config file
  alt File exists
    InitCMD->>User: Return ErrFileExists
  else File not found or other error
    InitCMD->>OS: Create config file
    InitCMD->>OS: Chmod to 0o600
    InitCMD->>OS: Write InitConfigData
    InitCMD->>User: Return success or wrapped error
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A new command springs to life today,
Creating configs in the CLI way,
With file perms locked and errors caught,
The init command, thoughtfully wrought! 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new Init command that creates a default configuration file.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch init-config

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/commands/init.go`:
- Around line 54-56: The deferred closure currently discards the error from
f.Close(); update the anonymous deferred function that takes f *os.File to
capture and handle the returned error (e.g., check cerr := f.Close(); if cerr !=
nil { log or wrap the error into the surrounding function's returned error or
call a logger like fmt.Fprintf(os.Stderr, ...) }) instead of ignoring it; ensure
you preserve the existing behavior when no error occurs and propagate or record
the close error so write/flush failures aren’t silently lost.
- Around line 41-61: The current init routine uses os.Stat then os.Create and a
separate f.Chmod which is TOCTOU-prone and leaves a permission window; replace
the os.Stat+os.Create+Chmod sequence with a single atomic open using
os.OpenFile(InitConfigFileName, os.O_CREATE|os.O_EXCL|os.O_WRONLY,
InitConfigFileMode) (or 0o600 if InitConfigFileMode is not appropriate), remove
the prior os.Stat branch, and map errors from OpenFile to the existing sentinel
errors (return ErrFileExists when the error indicates the file already exists;
wrap other errors as ErrCreate/ErrStat as appropriate), ensure you defer
f.Close() immediately after successful OpenFile and do not call Chmod
afterwards.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa39dc4a-1aee-471c-a8a0-dff1bf74ecf0

📥 Commits

Reviewing files that changed from the base of the PR and between a0468c2 and 572c8a2.

📒 Files selected for processing (3)
  • cmd/commands/init.go
  • cmd/root.go
  • pkg/validator/config.go

Comment thread cmd/commands/init.go Outdated
Comment thread cmd/commands/init.go Outdated
@thumbrise thumbrise merged commit 22c50fc into main May 28, 2026
4 checks passed
@thumbrise thumbrise deleted the init-config branch May 28, 2026 23:09
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@coderabbitai coderabbitai Bot mentioned this pull request May 29, 2026
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant