diff --git a/.gosurf.sample.yml b/.gosurf.sample.yml index 4700535..c85e88a 100644 --- a/.gosurf.sample.yml +++ b/.gosurf.sample.yml @@ -2,3 +2,4 @@ area: "4716" # North America region: "2081" # Southern California subregion: "2953" # South San Diego +days: 10 # Fetch 10 days of data for forecast, tide, etc diff --git a/README.md b/README.md index cb1c685..4f5dbcf 100644 --- a/README.md +++ b/README.md @@ -98,9 +98,9 @@ The CLI will read in the values to override the global flags' defaults (by flag Download the right binary (for example, `gosurf_darwin_amd64` for Mac) and move it to somewhere in your `$PATH` (so that it can be loaded into your command line environment). -For Mac, you might do something like to download `gosurf` 0.0.3: +For Mac, you might do something like to download `gosurf` 0.0.5: ``` -$ curl -L https://github.com/mhelmetag/gosurf/releases/download/0.0.3/gosurf_darwin_amd64 -o /usr/local/bin/gosurf +$ curl -L https://github.com/mhelmetag/gosurf/releases/download/0.0.5/gosurf_darwin_amd64 -o /usr/local/bin/gosurf $ chmod a+x /usr/local/bin/gosurf ``` diff --git a/main.go b/main.go index 8220b02..f054534 100644 --- a/main.go +++ b/main.go @@ -14,13 +14,14 @@ import ( "gopkg.in/urfave/cli.v2/altsrc" ) -const version = "0.0.4" +const version = "0.0.5" func main() { - var pType string var aID string var rID string var srID string + var pType string + var d int cfgFilepath, _ := homedir.Expand("~/.gosurf.yml") flags := []cli.Flag{ @@ -51,6 +52,15 @@ func main() { Destination: &srID, }, ), + altsrc.NewIntFlag( + &cli.IntFlag{ + Name: "days", + Aliases: []string{"d"}, + Value: 7, + Usage: "number of days to report (between 1 and 15)", + Destination: &d, + }, + ), &cli.StringFlag{ Name: "configfile", Aliases: []string{"c"}, @@ -107,7 +117,7 @@ func main() { return nil } - forecast(aID, rID, srID) + forecast(aID, rID, srID, d) return nil }, @@ -124,7 +134,7 @@ func main() { return nil } - tide(aID, rID, srID) + tide(aID, rID, srID, d) return nil }, @@ -148,7 +158,7 @@ func search(pType string, aID string, rID string) { } } -func forecast(aID string, rID string, srID string) { +func forecast(aID string, rID string, srID string, d int) { c, err := surflinef.DefaultClient() if err != nil { fmt.Println("There was an error while building the SurflineF client") @@ -156,9 +166,15 @@ func forecast(aID string, rID string, srID string) { return } + if !validDayAmount(d) { + fmt.Println("The number of days to report can only be between 1 and 15") + + return + } + q := surflinef.Query{ Resources: []string{"analysis"}, - Days: 7, + Days: d, Units: "e", FullAnalysis: true, } @@ -180,7 +196,7 @@ func forecast(aID string, rID string, srID string) { analysisToTable(f.Analysis) } -func tide(aID string, rID string, srID string) { +func tide(aID string, rID string, srID string, d int) { c, err := surflinef.DefaultClient() if err != nil { fmt.Println("There was an error while building the SurflineF client") @@ -188,9 +204,15 @@ func tide(aID string, rID string, srID string) { return } + if !validDayAmount(d) { + fmt.Println("The number of days to report can only be between 1 and 15") + + return + } + q := surflinef.Query{ Resources: []string{"tide"}, - Days: 7, + Days: d, Units: "e", FullAnalysis: true, } @@ -353,3 +375,13 @@ func filterPoints(ps []surflinef.DataPoint) []surflinef.DataPoint { func validPoint(p surflinef.DataPoint) bool { return p.Type == "Low" || p.Type == "High" } + +func validDayAmount(d int) bool { + if d < 1 { + return false + } else if d > 15 { + return false + } else { + return true + } +}