package cmd import ( "axolotl/output" "axolotl/service" "fmt" "os" "path/filepath" "github.com/spf13/cobra" ) var initCmd = &cobra.Command{ Use: "init [path]", Short: "Initialize a new database", Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { p := "." if len(args) > 0 { p = args[0] } dbPath := filepath.Join(p, ".ax.db") 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 { fmt.Fprintln(os.Stderr, "failed to initialize:", err) os.Exit(1) } output.PrintAction(cmd.OutOrStdout(), "Created", dbPath, false) }, } func init() { rootCmd.AddCommand(initCmd) }