Skip to content

Commit

Permalink
v0.3.0 release (#46)
Browse files Browse the repository at this point in the history
* fixes typo for 'type' flag resolves #34

Co-authored-by: Gabriel Fosse <[email protected]>

* add about command (#45)

* add parameter to countries table (#47)

Co-authored-by: Gabriel Fosse <[email protected]>
Co-authored-by: Gabriel Fosse <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2023
1 parent 5bd8916 commit eefb3af
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v0.3.0 - 2023-09-13

* Adds parameters to `countries list` table view resolved issue #32
* Fixes typo in `parameters` `--type` flag documentation resolved issue #34
* Removed parameters from `countries list` `--mini` table resolved issue #32
* Add `openaq about` command

## v0.2.0 - 2023-09-05

* Default value for `locations list` `--from` flag fixed issue #1
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ _the following only work on resource `list` calls_

### Commands

about
---

```sh
openaq about
```

Provides a description of the OpenAQ CLI.


configure
---
__api-key__
Expand Down
31 changes: 31 additions & 0 deletions cmd/about/about.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package about

import (
"fmt"

"github.com/spf13/cobra"
)

var aboutHeader = `
___ _ ___ ____ _ ___
/ _ \ _ __ ___ _ __ / \ / _ \ / ___| | |_ _|
| | | | '_ \ / _ | '_ \ / _ \| | | | | | | | | |
| |_| | |_) | __| | | |/ ___ | |_| | | |___| |___ | |
\___/| .__/ \___|_| |_/_/ \_\__\_\ \____|_____|___|
|_|
The OpenAQ CLI is a command line interface tool to access the OpenAQ API.
The source code is open source and available on github at:
https://github.com/openaq/openaq-cli
`

var AboutCmd = &cobra.Command{
Use: "about",
Short: "About the OpenAQ CLI",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(aboutHeader)
},
}
2 changes: 1 addition & 1 deletion cmd/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func AddParameters(cmd *cobra.Command) {
}

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

func AddProviders(cmd *cobra.Command) {
Expand Down
18 changes: 15 additions & 3 deletions cmd/internal/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

"github.com/nwidger/jsoncolor"
Expand All @@ -16,7 +17,7 @@ import (
)

var countriesHeaders = []string{"countries_id", "iso_code", "name", "datetime_first", "datetime_last", "parameters", "locations_count", "measurements_count", "providers_count"}
var countriesMiniHeaders = []string{"countries_id", "iso_code", "name", "parameters"}
var countriesMiniHeaders = []string{"countries_id", "iso_code", "name"}
var locationsHeaders = []string{"locations_id", "name", "countries_id", "country_iso", "country_name", "latitude", "longitude"}
var measurementsParametersHeaders = []string{"parameter_id", "parameter_name", "parameter_units", "parameter_display_name"}
var measurementsPeriodHeaders = []string{"periodLabel", "periodInterval", "periodDatetimeFromUTC", "periodDatetimeFromLocal", "periodDatetimeToUTC", "periodDatetimeToLocal"}
Expand Down Expand Up @@ -161,14 +162,26 @@ func writeCountriesTable(countries *openaq.CountriesResponse, headers []string)
row = append(row, s.Name)
row = append(row, s.DatetimeFirst.Format(time.RFC3339))
row = append(row, s.DatetimeLast.Format(time.RFC3339))
row = append(row, "")
row = append(row, joinParamDisplayNames(s.Parameters))
row = append(row, strconv.FormatInt(s.LocationsCount, 10))
row = append(row, strconv.FormatInt(s.MeasurementsCount, 10))
row = append(row, strconv.FormatInt(s.ProvidersCount, 10))
tw.AppendRow(row)
}
return tw.Render()
}

func joinParamDisplayNames(params []openaq.ParameterBase) string {
var builder strings.Builder
for i, param := range params {
builder.WriteString(param.DisplayName)
if i < len(params)-1 {
builder.WriteString(", ")
}
}
return builder.String()
}

func writeMiniCountriesTable(countries *openaq.CountriesResponse, headers []string) string {
var columns = len(headers)
tw := table.NewWriter()
Expand All @@ -178,7 +191,6 @@ func writeMiniCountriesTable(countries *openaq.CountriesResponse, headers []stri
row = append(row, strconv.FormatInt(s.ID, 10))
row = append(row, s.Code)
row = append(row, s.Name)
row = append(row, "")
tw.AppendRow(row)
}
return tw.Render()
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/openaq/openaq-cli/cmd/about"
"github.com/openaq/openaq-cli/cmd/configure"
"github.com/openaq/openaq-cli/cmd/countries"
"github.com/openaq/openaq-cli/cmd/locations"
Expand Down Expand Up @@ -52,6 +53,7 @@ func init() {
rootCmd.AddCommand(parameters.ParametersCmd)
rootCmd.AddCommand(providers.ProvidersCmd)
rootCmd.AddCommand(version.VersionCmd)
rootCmd.AddCommand(about.AboutCmd)
}

func initConfig() {
Expand Down

0 comments on commit eefb3af

Please sign in to comment.