4bfc246be4
REQ-041: ORCA_HOME is now the single namespace root for all components
(db, certs, init, daemon). store.Open("") and init command both
route through certpaths.Dir()/DBPath() instead of hardcoding ~/.orca.
Backward compatible: empty ORCA_HOME -> ~/.orca.
REQ-042: --system persistent flag on rootCmd sets ORCA_HOME=/root/.orca
via PersistentPreRunE. Errors on conflict with pre-set ORCA_HOME.
Tests: 7 new tests in namespace_test.go (default, ORCA_HOME override,
--system sets root, conflict detection, init --json, flag registered).
Full suite passes (no regressions).
Docs: docs/namespace.md covers default, ORCA_HOME, --system, ORCA_DB,
resolution order, and path layout tables.
---ci---
project: orca
phase: 1
milestone: v0.5
status: verify
---/ci---
36 lines
786 B
Go
36 lines
786 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"git.cloudinit.dev/coreci/orca/internal/certpaths"
|
|
)
|
|
|
|
var initCmd = &cobra.Command{
|
|
Use: "init",
|
|
Short: "Initialize local orca state directory",
|
|
Long: "Create the local orca state directory (honors $ORCA_HOME; defaults to ~/.orca) and write a default config file.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
orcaDir := certpaths.Dir()
|
|
if err := os.MkdirAll(orcaDir, 0o755); err != nil {
|
|
return fmt.Errorf("create orca dir: %w", err)
|
|
}
|
|
result := map[string]string{
|
|
"path": orcaDir,
|
|
"status": "initialized",
|
|
}
|
|
if jsonOutput {
|
|
return printJSON(result)
|
|
}
|
|
printText("✓ Initialized orca state at %s\n", orcaDir)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(initCmd)
|
|
}
|