Skip to content

Commit

Permalink
add config for days, update README and gosurf config file sample
Browse files Browse the repository at this point in the history
  • Loading branch information
mhelmetag committed Jun 27, 2018
1 parent 7a47339 commit 1ed4abb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gosurf.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
48 changes: 40 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -107,7 +117,7 @@ func main() {
return nil
}

forecast(aID, rID, srID)
forecast(aID, rID, srID, d)

return nil
},
Expand All @@ -124,7 +134,7 @@ func main() {
return nil
}

tide(aID, rID, srID)
tide(aID, rID, srID, d)

return nil
},
Expand All @@ -148,17 +158,23 @@ 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")

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,
}
Expand All @@ -180,17 +196,23 @@ 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")

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,
}
Expand Down Expand Up @@ -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
}
}

0 comments on commit 1ed4abb

Please sign in to comment.