var kindlePathCmd = &cobra.Command{ Use: "kindle:path", Short: "Import from Kindle's vocabulary", Run: func(cmd *cobra.Command, args []string) { const vocabularySubPath string = "system/vocabulary/vocab.db" kindleMountPoint = strings.TrimSpace(kindleMountPoint) if kindleMountPoint == "" { log.Fatalln("Path to Kindle should not be empty") } database := path.Join(kindleMountPoint, vocabularySubPath) if _, err := os.Stat(database); os.IsNotExist(err) { log.Fatalln("Cannot find vocabulary in " + database) } words := kindle.GetWords(database) for _, word := range words { lingualeo.AddWord(word.Word) log.Println("Imported: " + word.Word) } }, } func init() { importCmd.AddCommand(kindlePathCmd) kindlePathCmd.Flags().StringVarP(&kindleMountPoint, "path", "p", "", "Path to Kindle") }
if err != nil { log.Fatal(err) } defer func() { err := file.Close() if err != nil { log.Fatal(err) } }() scanner := bufio.NewScanner(file) var word string for scanner.Scan() { word = strings.TrimSpace(scanner.Text()) leo.AddWord(word) log.Println("Imported: " + word) } if err := scanner.Err(); err != nil { log.Fatal(err) } }, } func init() { importCmd.AddCommand(importFileListCmd) importFileListCmd.Flags().StringVarP(&filePath, "file", "f", "", "File path") }