Skip to content

Commit

Permalink
v0.2.0 release (#30)
Browse files Browse the repository at this point in the history
* default from flag and check for missing value #fixes #1 (#11)

* update measurements mini datetimes to RFC3339 formatting fixes #2 (#12)

* added `--iso` flag to `locations` sub-command (#20)

---------

Co-authored-by: Gabriel Fosse <kraken+majesticio@users.noreply.github.com>

* add providers resource with list and get commands resolves #13 (#21)

* add countries mini option resolves #7 (#23)

* add proivders table output (#24)

* Measurements mini csv (#25)

* add proivders table output

* add mini csv option for measurements resolves #22

* refactor client and include user-agent (#26)

* Refactor/flags (#27)

* refactor client and include user-agent

* refactor flags to separate flags package resolves #19

* add radius search to locations list (#28)

* add bounding box on locations (#29)

---------

Co-authored-by: Gabriel Fosse <67290377+majesticio@users.noreply.github.com>
Co-authored-by: Gabriel Fosse <kraken+majesticio@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 6, 2023
1 parent 19a49c3 commit 3002f59
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 142 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ openaq countries list

Provides a list of countries.


__flags__

`--mini` - provides a miniature/simplified version of the countries resource including only the countries ID, ISO code, name, and parameters

---


Expand Down Expand Up @@ -112,6 +117,14 @@ __flags__

`--providers` - filter locations by one or more comma-delimited `providers ID` e.g. 1,2,3

`--iso` - Filter the results to a specific country using ISO 3166-1 alpha-2 code

`--radius` - The radius in meters to search around the `--coordinates` center point. Must be used with `--coordinates`

`--coordinates` - The center point coordinates for the radius search in form latitude,longitude i.e. y,x. Must be used with `--radius`

`--bbox` - Filter results to those contained within a spatial bounding box, in form minx,miny,maxx,maxy. Cannot be used with `--radius`/`--coordinates`

---

```sh
Expand Down
19 changes: 10 additions & 9 deletions cmd/countries/countries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ import (
"github.com/openaq/openaq-go"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"

flags "github.com/openaq/openaq-cli/cmd/flags"
internal "github.com/openaq/openaq-cli/cmd/internal"
)

func init() {

flags.AddLimit(listCmd)
flags.AddPage(listCmd)

CountriesCmd.AddCommand(listCmd)
CountriesCmd.AddCommand(getCmd)

flags.AddFormat(CountriesCmd)
flags.AddMini(CountriesCmd)
}

func parseFlags(flags *pflag.FlagSet) (*openaq.CountryArgs, error) {
Expand Down Expand Up @@ -55,10 +62,7 @@ var listCmd = &cobra.Command{
Short: "List countries",
Long: `List countries`,
Run: func(cmd *cobra.Command, args []string) {
config := openaq.Config{
APIKey: viper.GetString("api-key"),
}
client, err := openaq.NewClient(config)
client, err := internal.SetupClient()
if err != nil {
fmt.Println("cannot initialize client")
}
Expand Down Expand Up @@ -86,10 +90,7 @@ var getCmd = &cobra.Command{
if err != nil {
panic(err)
}
config := openaq.Config{
APIKey: viper.GetString("api-key"),
}
client, err := openaq.NewClient(config)
client, err := internal.SetupClient()
if err != nil {
fmt.Println("cannot initialize client")
}
Expand Down
68 changes: 0 additions & 68 deletions cmd/flags.go

This file was deleted.

88 changes: 88 additions & 0 deletions cmd/flags/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package flags

import (
"github.com/spf13/cobra"
)

var pretty bool
var json bool
var csv bool
var mini bool
var limit int64
var page int64
var fromDate string
var toDate string
var periodName string
var parameterType string
var isoCode string
var radius int64
var coordinates []float64
var bbox []float64

var countriesIDs []int64
var providersIDs []int64
var parametersIDs []int64

func AddCountries(cmd *cobra.Command) {
cmd.PersistentFlags().Int64SliceVar(&countriesIDs, "countries", []int64{}, "filter results by country ID(s)")
}

func AddParameters(cmd *cobra.Command) {
cmd.PersistentFlags().Int64SliceVar(&parametersIDs, "parameters", []int64{}, "filter results by parameters ID(s)")
}

func AddParametersType(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&parameterType, "type", "", "filter parameters to either `pollutants` or `meteorolgoical` parameters")
}

func AddProviders(cmd *cobra.Command) {
cmd.PersistentFlags().Int64SliceVar(&providersIDs, "providers", []int64{}, "filter results by provider by provider ID(s)")
}

func AddFormat(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&json, "json", false, "output results as JSON")
cmd.PersistentFlags().BoolVar(&csv, "csv", false, "output results as CSV (Comma Separated Values)")
cmd.PersistentFlags().BoolVar(&pretty, "pretty", false, "pretty print")
cmd.MarkFlagsMutuallyExclusive("json", "csv")
cmd.MarkFlagsMutuallyExclusive("pretty", "csv")
}

func AddLimit(cmd *cobra.Command) {
cmd.PersistentFlags().Int64Var(&limit, "limit", 100, "limit")
}

func AddPage(cmd *cobra.Command) {
cmd.PersistentFlags().Int64Var(&page, "page", 1, "page")
}

func AddFromDate(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&fromDate, "from", "2000-01-01", "from")
}

func AddToDate(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&toDate, "to", "", "to")
}

func AddPeriodName(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&periodName, "period-name", "", "period-name")
}

func AddMini(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&mini, "mini", false, "mini")
}

func AddIsoCode(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&isoCode, "iso", "", "Limit the results to a specific country using ISO 3166-1 alpha-2 code")
}

func AddRadiusSearch(cmd *cobra.Command) {
cmd.PersistentFlags().Int64Var(&radius, "radius", 0, "distance in meters to search around `coordinates`")
cmd.PersistentFlags().Float64SliceVar(&coordinates, "coordinates", nil, "Coordinate pair of center point to perform radius search. In form latitude,longitude i.e. y,x")
cmd.MarkFlagsRequiredTogether("radius", "coordinates")
}

func AddBBox(cmd *cobra.Command) {
cmd.PersistentFlags().Float64SliceVar(&bbox, "bbox", nil, "A bounding box to search within in form minx,miny,maxx,maxy")
cmd.MarkFlagsMutuallyExclusive("radius", "bbox")
cmd.MarkFlagsMutuallyExclusive("coordinates", "bbox")
}
Loading

0 comments on commit 3002f59

Please sign in to comment.