diff --git a/README.md b/README.md index b09abe4..37cc0da 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,11 @@ The first run of the command will take some time to cache the text extracted fro # How to clear the cache? -To clear the cache (which contains text extracted from PDF), you may safely remove the file -``~/.cache/fast-p-pdftotext-output/fast-p_cached_pdftotext_output.db``, or -``~/.cache/fast-p_cached_pdftotext_output.db`` in older version. +To clear the cache (which contains text extracted from PDF), you can run 'fast-p --clear-cache'. This will safely remove the file located at: +``~/.cache/fast-p-pdftotext-output/fast-p_cached_pdftotext_output.db`` + +For older versions, please manually delete the cache file found at +``~/.cache/fast-p_cached_pdftotext_output.db`` # Launch with keyboard shortcut in Ubuntu diff --git a/main.go b/main.go index 2e598e5..6c602a0 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "os" + "flag" "path/filepath" "os/exec" "bufio" @@ -32,6 +33,25 @@ func hash_file_xxhash(filePath string) (string, error) { } func main() { + version := flag.Bool("version", false, "Display program version") + clearCache := flag.Bool("clear-cache", false, "Delete cache file located at: \n~/.cache/fast-p-pdftotext-output/fast-p_cached_pdftotext_output.db") + flag.Parse() + + if *version != false { + fmt.Printf("v.0.2.4 \nhttps://github.com/bellecp/fast-p\n") + os.Exit(0) + } + + if *clearCache !=false { + removePath, err := homedir.Expand("~/.cache/fast-p-pdftotext-output/fast-p_cached_pdftotext_output.db") + if err != nil { + log.Fatal(err) + os.Exit(1) + } + os.Remove(removePath) + os.Exit(0) + } + // Create ~/.cache folder if does not exist // https://stackoverflow.com/questions/37932551/mkdir-if-not-exists-using-golang cachePath, err := homedir.Expand("~/.cache/fast-p-pdftotext-output/")