From 7d6b07ccee94cb1c4459270e07359fdeb097d182 Mon Sep 17 00:00:00 2001 From: Corey Penford Date: Tue, 9 Jul 2019 09:13:59 -0400 Subject: [PATCH] Add the following flags to the fast-p binary --version, --clear-cache, --help --- README.md | 8 +++++--- main.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) 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/")