initialize

package
v0.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package initialize creates the ~/.marunage/ on-disk layout that `marunage init` (PR-33) is responsible for. Splitting the side-effecting work out of the CLI command keeps cobra-free unit tests on top of the real filesystem and lets future callers (Web UI, tests for downstream commands) provision a fresh marunage home without re-implementing the invariants here.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMode = errors.New("invalid permission mode")

ErrInvalidMode is returned when Options.Mode is set to a value outside the documented permission-mode whitelist. Exposing it as a sentinel lets the CLI layer match with errors.Is and surface a non-zero exit code without re-validating the input itself.

Functions

func ResolveMode

func ResolveMode(mode string) (string, error)

ResolveMode applies the same defaulting + whitelist check Run does, returned as a separate step so callers (the CLI) can validate user input *before* opening side-effecting writers like the audit log. Empty input resolves to the documented default ("bypass"); anything outside the whitelist returns ErrInvalidMode.

Types

type Options

type Options struct {
	Home    string
	Mode    string
	Auditor config.Auditor
}

Options is the inject-the-world struct Run takes. Home is the only required field in production; tests pass it as t.TempDir() to avoid touching the developer's real ~/.marunage. Mode lets the CLI relay the user's permission-mode choice without coupling this package to cobra; an empty Mode resolves to the documented default ("bypass").

Auditor is optional and omitted by callers that genuinely have no audit log yet (single-test scenarios). Production wires in *logging.AuditLog so the "No silent execution" invariant from docs/requirement.md applies to init too.

type Result

type Result struct {
	ConfigPath    string
	ConfigCreated bool
}

Result tells the caller what happened so the CLI can render an idempotency-aware human message ("created" vs "already initialized") without the package re-deciding by re-stat-ing the same files.

func Run

func Run(opts Options) (Result, error)

Run is the entry point: ensure the marunage home layout exists, write a default config.toml the first time, and report what changed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL