39 lines
834 B
Go
39 lines
834 B
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var initCmd = &cobra.Command{
|
|
Use: "init",
|
|
Short: "Initialize local orca state directory",
|
|
Long: "Create the local orca state directory at ~/.orca/ and write a default config file.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
return fmt.Errorf("get home dir: %w", err)
|
|
}
|
|
orcaDir := filepath.Join(home, ".orca")
|
|
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)
|
|
}
|