package cmd import ( "fmt" "os" fp "path/filepath" "strings" "time" "github.com/go-shiori/shiori/internal/database" "github.com/go-shiori/shiori/internal/model" "github.com/spf13/cobra" ) func exportCmd() *cobra.Command { cmd := &cobra.Command{ Use: "export target-file", Short: "Export bookmarks into HTML file in Netscape Bookmark format", Args: cobra.ExactArgs(1), Run: exportHandler, } return cmd } func exportHandler(cmd *cobra.Command, args []string) { // Fetch bookmarks from database bookmarks, err := db.GetBookmarks(cmd.Context(), database.GetBookmarksOptions{}) if err != nil { cError.Printf("Failed to get bookmarks: %v\n", err) os.Exit(1) } if len(bookmarks) == 0 { cError.Println("No saved bookmarks yet") return } // Make sure destination directory exist dstDir := fp.Dir(args[0]) if err := os.MkdirAll(dstDir, os.ModePerm); err != nil { cError.Printf("Error crating destination directory: %s", err) } // Create destination file dstFile, err := os.Create(args[0]) if err != nil { cError.Printf("Failed to create destination file: %v\n", err) os.Exit(1) } defer dstFile.Close() // Write exported bookmark to file fmt.Fprintln(dstFile, ``+ ``+ ``+ `