Skip to content

Commit

Permalink
clg: prettier city output / formatting / show temperature / adjusted …
Browse files Browse the repository at this point in the history
…readme / added "integration-test" bash script
  • Loading branch information
Claude Gex committed Jun 12, 2018
1 parent 8f49add commit caf96ff
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 9 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ Obenuse, nid?

## Grundsätzlechs

Usfüüährig uf dr Kommandozile wie fougt:
Usfüüährig uf dr Kommandozile wie fougt (für Bärn):

aareguru

Oder

aareguru schribmaschine

Weli Städt gits aui?

aareguru cities

Tämperatur ds Thun?

aareguru thun

Spicke duesch grundsätzläch so:

aareguru --help
Expand Down
5 changes: 5 additions & 0 deletions Release.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Preparation

./pre-release.sh
./integration-tests.sh

# Releasing

Precondition - you need access to the github repository as well as to the corresponding homebrew-tap repository. You should have an access token and have it exported
Expand Down
4 changes: 3 additions & 1 deletion api/AareGuruApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
)

// AareGuruResponse root type of the aare.guru response
Expand Down Expand Up @@ -63,7 +64,7 @@ func AskAareGuru(proxy *string, city *string, aareGuruResponseChannel chan<- Aar

client := createHTTPClient(proxy)

url := config.EndpointURL + "&city=" + *city
url := config.EndpointURL + "&city=" + strings.ToLower(*city)

response, err := client.Get(url)
if err != nil {
Expand Down Expand Up @@ -98,6 +99,7 @@ type City struct {
City string
Name string
Longname string
Aare float32
}

// AskAareGuruForCities ask aare.guru for cities, returns an CitiesResponse
Expand Down
61 changes: 61 additions & 0 deletions integration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

function pause()
{
while true; do
read -p "Continue? y/n: " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
}

echo "go run Aareguru.go --help"
go run Aareguru.go --help

pause

echo "go run Aareguru.go cities"
go run Aareguru.go cities

pause

echo "go run Aareguru.go cities -f"
go run Aareguru.go cities -f

pause

echo "go run Aareguru.go"
go run Aareguru.go

pause

echo "go run Aareguru.go standard"
go run Aareguru.go standard

pause

echo "go run Aareguru.go standard -l"
go run Aareguru.go standard -l

pause

echo "go run Aareguru.go standard -f"
go run Aareguru.go standard -f

pause

echo "go run Aareguru.go schribmaschine"
go run Aareguru.go schribmaschine

pause

echo "go run Aareguru.go standard biel"
go run Aareguru.go standard biel

pause

echo "go run Aareguru.go schribmaschine interlaken"
go run Aareguru.go schribmaschine interlaken
44 changes: 38 additions & 6 deletions outcities/CitiesOutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package outcities

import (
"../api"
"../asciiart"
"../console"
"../texts"
"fmt"
"strconv"
"sync"
)

Expand Down Expand Up @@ -35,12 +39,40 @@ func readData(citiesResponseChannel chan api.CitiesResponse, errChannel chan str
}

func printOutput(citiesResponse api.CitiesResponse) {
fmt.Printf("%-10s | %-10s | %s\n", "City *", "Name", "Gnaue Standort")
fmt.Printf("%-10s | %-10s | %s\n", "----------", "----------", "----------------------")
for _, elem := range citiesResponse.Cities {
fmt.Printf("%-10s | %-10s | %s\n", elem.City, elem.Name, elem.Longname)
fmt.Println(boxHorizontalLine())
fmt.Print(console.CBlue(asciiart.Banner))

fmt.Println(fmt.Sprintf("|%-11s+%-12s+%6s+%s|", "------------", "------------", "------", "---------------------------------------"))
fmt.Println(box(fmt.Sprintf("%-10s | %-10s | %4s | %s", "City *", "Name", texts.DegreeCelsiusLabel, "Gnaue Standort")))
fmt.Println(fmt.Sprintf("|%-11s+%-12s+%6s+%s|", "------------", "------------", "------", "---------------------------------------"))
for _, city := range citiesResponse.Cities {
fmt.Println(box(
fmt.Sprintf("%-10s | %-10s | %s | %s",
city.City,
city.Name,
console.CBlue(fmt.Sprintf("%4.1f", city.Aare)),
city.Longname),
console.CBlue("")))
}

fmt.Println(boxHorizontalLine())
fmt.Println(box("* gib das im Command aus `city` argument a"))
fmt.Println(boxHorizontalLine())
fmt.Println()
fmt.Println("* gib das im command aus `city` argument a")
fmt.Println()
}

func boxHorizontalLine() string {
return "+------------------------------------------------------------------------+"
}

func box(str string, colorChars ...string) string {
return fmt.Sprintf("| %-"+strconv.Itoa(70+colorCharsLength(colorChars...))+"s |", str)
}

func colorCharsLength(colorChars ...string) int {
var colorCharsLen = 0
for _, element := range colorChars {
colorCharsLen += len(element)
}
return colorCharsLen
}
2 changes: 1 addition & 1 deletion pre-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

gofmt -w .

find . -type d | xargs -L 1 golint
find . -type d | xargs -L 1 ~/go/bin/golint

0 comments on commit caf96ff

Please sign in to comment.