From 3326769c24c9ba670ef0e30f90ef2957db3c149f Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 15 Mar 2020 17:16:04 +0530 Subject: Port path-only to cetus-nasa --- README.org | 4 ++++ cmd/cetus-nasa/cetus-nasa.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/README.org b/README.org index df511af..ce251dd 100644 --- a/README.org +++ b/README.org @@ -77,6 +77,10 @@ cetus-nasa -api https://api.nasa.gov/planetary/apod \ # don't set background, just fetch information cetus-nasa -fetch-only +# don't set background, just fetch & print only the path (useful in +# scripts) +cetus-nasa -fetch-only -path-only + # don't output anything cetus-nasa -quiet diff --git a/cmd/cetus-nasa/cetus-nasa.go b/cmd/cetus-nasa/cetus-nasa.go index bb7ad6a..6610bba 100644 --- a/cmd/cetus-nasa/cetus-nasa.go +++ b/cmd/cetus-nasa/cetus-nasa.go @@ -29,6 +29,7 @@ var ( quiet bool version bool fetchOnly bool + pathOnly bool api string apiKey string @@ -91,6 +92,7 @@ func parseFlags() { dateHelp = fmt.Sprintf("Choose a random date between 1995-06-16 & %s", time.Now().UTC().Format("2006-01-02")) flag.BoolVar(&random, "random", false, dateHelp) + flag.BoolVar(&pathOnly, "path-only", false, "Print only path of the image") flag.StringVar(&api, "api", "https://api.nasa.gov/planetary/apod", "APOD API URL") flag.StringVar(&apiKey, "api-key", "DEMO_KEY", "api.nasa.gov key for expanded usage") @@ -107,6 +109,10 @@ func printDetails(apodRes nasa.APOD) { if quiet { return } + if pathOnly { + cetus.PrintPath(apodPhoto.HDURL) + return + } fmt.Printf("Title: %s\n\n", apodRes.Title) fmt.Printf("Copyright: %s\n", apodRes.Copyright) fmt.Printf("Date: %s\n\n", apodRes.Date) -- cgit 1.4.1-2-gfad0