Files
ax/cmd/init.go

34 lines
749 B
Go
Raw Normal View History

2026-03-26 12:48:47 +00:00
package cmd
import (
"axolotl/output"
"axolotl/service"
2026-03-26 12:48:47 +00:00
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
)
var initCmd = &cobra.Command{
Use: "init [path]", Short: "Initialize a new database", Args: cobra.MaximumNArgs(1),
2026-03-26 12:48:47 +00:00
Run: func(cmd *cobra.Command, args []string) {
p := "."
2026-03-26 12:48:47 +00:00
if len(args) > 0 {
p = args[0]
2026-03-26 12:48:47 +00:00
}
dbPath := filepath.Join(p, ".ax.db")
2026-03-26 12:48:47 +00:00
if _, err := os.Stat(dbPath); err == nil {
fmt.Fprintln(os.Stderr, "database already exists:", dbPath)
os.Exit(1)
}
if err := service.InitNodeService(dbPath); err != nil {
2026-03-26 12:48:47 +00:00
fmt.Fprintln(os.Stderr, "failed to initialize:", err)
os.Exit(1)
}
output.PrintAction(cmd.OutOrStdout(), "Created", dbPath, false)
2026-03-26 12:48:47 +00:00
},
}
func init() { rootCmd.AddCommand(initCmd) }