From ddbef09f66e71c2e3172eb876c81a86e89cab7dc Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 14 Mar 2020 23:48:47 +0530 Subject: Add version flag --- cmd/cetus-nasa/cetus-nasa.go | 33 +++++++++++++++++++++------------ pkg/background.go | 27 --------------------------- pkg/background/background.go | 27 +++++++++++++++++++++++++++ pkg/cetus/cetus.go | 22 ++++++++++++++++++++++ 4 files changed, 70 insertions(+), 39 deletions(-) delete mode 100644 pkg/background.go create mode 100644 pkg/background/background.go create mode 100644 pkg/cetus/cetus.go diff --git a/cmd/cetus-nasa/cetus-nasa.go b/cmd/cetus-nasa/cetus-nasa.go index 96b83fc..7eb80c2 100644 --- a/cmd/cetus-nasa/cetus-nasa.go +++ b/cmd/cetus-nasa/cetus-nasa.go @@ -20,12 +20,14 @@ import ( "log" "time" - "framagit.org/andinus/cetus/pkg" + "framagit.org/andinus/cetus/pkg/background" + "framagit.org/andinus/cetus/pkg/cetus" "framagit.org/andinus/cetus/pkg/nasa" ) var ( quiet bool + version bool fetchOnly bool api string @@ -38,19 +40,13 @@ var ( ) func main() { - var ( - picturePath string - apodRes nasa.APOD - err error - apodInfo map[string]string - ) - - dateHelp = fmt.Sprintf("Choose a random date between 1995-06-16 & %s", - time.Now().UTC().Format("2006-01-02")) - dateDefault = time.Now().UTC().Format("2006-01-02") - parseFlags() + if version { + cetus.Version() + return + } + // Convert timeout to seconds timeout = timeout * time.Second @@ -58,6 +54,13 @@ func main() { date = nasa.RandDate() } + var ( + picturePath string + apodRes nasa.APOD + err error + apodInfo map[string]string + ) + apodInfo = make(map[string]string) apodInfo["api"] = api apodInfo["apiKey"] = apiKey @@ -92,11 +95,17 @@ func main() { func parseFlags() { flag.BoolVar(&quiet, "quiet", false, "No output") + flag.BoolVar(&version, "version", false, "Cetus version") flag.BoolVar(&fetchOnly, "fetch-only", false, "Don't set background, only fetch info") + + 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.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") + + dateDefault = time.Now().UTC().Format("2006-01-02") flag.StringVar(&date, "date", dateDefault, "Date of the APOD image to retrieve") flag.DurationVar(&timeout, "timeout", 32*time.Second, "Timeout for http client in seconds") diff --git a/pkg/background.go b/pkg/background.go deleted file mode 100644 index c6000ff..0000000 --- a/pkg/background.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2020, Andinus - -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. - -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -package background - -import "os/exec" - -// Set calls feh to set the background -func Set(path string) error { - feh, err := exec.LookPath("feh") - if err != nil { - return err - } - err = exec.Command(feh, "--bg-fill", path).Run() - return err -} diff --git a/pkg/background/background.go b/pkg/background/background.go new file mode 100644 index 0000000..c6000ff --- /dev/null +++ b/pkg/background/background.go @@ -0,0 +1,27 @@ +// Copyright (c) 2020, Andinus + +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. + +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +package background + +import "os/exec" + +// Set calls feh to set the background +func Set(path string) error { + feh, err := exec.LookPath("feh") + if err != nil { + return err + } + err = exec.Command(feh, "--bg-fill", path).Run() + return err +} diff --git a/pkg/cetus/cetus.go b/pkg/cetus/cetus.go new file mode 100644 index 0000000..5ebbb63 --- /dev/null +++ b/pkg/cetus/cetus.go @@ -0,0 +1,22 @@ +// Copyright (c) 2020, Andinus + +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. + +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +package cetus + +import "fmt" + +// Version prints cetus version +func Version() { + fmt.Println("Cetus v0.4.0") +} -- cgit 1.4.1-2-gfad0