Skip to content

Commit caf96ff

Browse files
author
Claude Gex
committed
clg: prettier city output / formatting / show temperature / adjusted readme / added "integration-test" bash script
1 parent 8f49add commit caf96ff

6 files changed

Lines changed: 121 additions & 9 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,22 @@ Obenuse, nid?
4040

4141
## Grundsätzlechs
4242

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

4545
aareguru
4646

47+
Oder
48+
49+
aareguru schribmaschine
50+
51+
Weli Städt gits aui?
52+
53+
aareguru cities
54+
55+
Tämperatur ds Thun?
56+
57+
aareguru thun
58+
4759
Spicke duesch grundsätzläch so:
4860

4961
aareguru --help

Release.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Preparation
2+
3+
./pre-release.sh
4+
./integration-tests.sh
5+
16
# Releasing
27

38
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

api/AareGuruApi.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io/ioutil"
88
"net/http"
99
"net/url"
10+
"strings"
1011
)
1112

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

6465
client := createHTTPClient(proxy)
6566

66-
url := config.EndpointURL + "&city=" + *city
67+
url := config.EndpointURL + "&city=" + strings.ToLower(*city)
6768

6869
response, err := client.Get(url)
6970
if err != nil {
@@ -98,6 +99,7 @@ type City struct {
9899
City string
99100
Name string
100101
Longname string
102+
Aare float32
101103
}
102104

103105
// AskAareGuruForCities ask aare.guru for cities, returns an CitiesResponse

integration-tests.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
function pause()
4+
{
5+
while true; do
6+
read -p "Continue? y/n: " yn
7+
case $yn in
8+
[Yy]* ) break;;
9+
[Nn]* ) exit;;
10+
* ) echo "Please answer yes or no.";;
11+
esac
12+
done
13+
}
14+
15+
echo "go run Aareguru.go --help"
16+
go run Aareguru.go --help
17+
18+
pause
19+
20+
echo "go run Aareguru.go cities"
21+
go run Aareguru.go cities
22+
23+
pause
24+
25+
echo "go run Aareguru.go cities -f"
26+
go run Aareguru.go cities -f
27+
28+
pause
29+
30+
echo "go run Aareguru.go"
31+
go run Aareguru.go
32+
33+
pause
34+
35+
echo "go run Aareguru.go standard"
36+
go run Aareguru.go standard
37+
38+
pause
39+
40+
echo "go run Aareguru.go standard -l"
41+
go run Aareguru.go standard -l
42+
43+
pause
44+
45+
echo "go run Aareguru.go standard -f"
46+
go run Aareguru.go standard -f
47+
48+
pause
49+
50+
echo "go run Aareguru.go schribmaschine"
51+
go run Aareguru.go schribmaschine
52+
53+
pause
54+
55+
echo "go run Aareguru.go standard biel"
56+
go run Aareguru.go standard biel
57+
58+
pause
59+
60+
echo "go run Aareguru.go schribmaschine interlaken"
61+
go run Aareguru.go schribmaschine interlaken

outcities/CitiesOutput.go

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package outcities
22

33
import (
44
"../api"
5+
"../asciiart"
6+
"../console"
7+
"../texts"
58
"fmt"
9+
"strconv"
610
"sync"
711
)
812

@@ -35,12 +39,40 @@ func readData(citiesResponseChannel chan api.CitiesResponse, errChannel chan str
3539
}
3640

3741
func printOutput(citiesResponse api.CitiesResponse) {
38-
fmt.Printf("%-10s | %-10s | %s\n", "City *", "Name", "Gnaue Standort")
39-
fmt.Printf("%-10s | %-10s | %s\n", "----------", "----------", "----------------------")
40-
for _, elem := range citiesResponse.Cities {
41-
fmt.Printf("%-10s | %-10s | %s\n", elem.City, elem.Name, elem.Longname)
42+
fmt.Println(boxHorizontalLine())
43+
fmt.Print(console.CBlue(asciiart.Banner))
44+
45+
fmt.Println(fmt.Sprintf("|%-11s+%-12s+%6s+%s|", "------------", "------------", "------", "---------------------------------------"))
46+
fmt.Println(box(fmt.Sprintf("%-10s | %-10s | %4s | %s", "City *", "Name", texts.DegreeCelsiusLabel, "Gnaue Standort")))
47+
fmt.Println(fmt.Sprintf("|%-11s+%-12s+%6s+%s|", "------------", "------------", "------", "---------------------------------------"))
48+
for _, city := range citiesResponse.Cities {
49+
fmt.Println(box(
50+
fmt.Sprintf("%-10s | %-10s | %s | %s",
51+
city.City,
52+
city.Name,
53+
console.CBlue(fmt.Sprintf("%4.1f", city.Aare)),
54+
city.Longname),
55+
console.CBlue("")))
4256
}
57+
58+
fmt.Println(boxHorizontalLine())
59+
fmt.Println(box("* gib das im Command aus `city` argument a"))
60+
fmt.Println(boxHorizontalLine())
4361
fmt.Println()
44-
fmt.Println("* gib das im command aus `city` argument a")
45-
fmt.Println()
62+
}
63+
64+
func boxHorizontalLine() string {
65+
return "+------------------------------------------------------------------------+"
66+
}
67+
68+
func box(str string, colorChars ...string) string {
69+
return fmt.Sprintf("| %-"+strconv.Itoa(70+colorCharsLength(colorChars...))+"s |", str)
70+
}
71+
72+
func colorCharsLength(colorChars ...string) int {
73+
var colorCharsLen = 0
74+
for _, element := range colorChars {
75+
colorCharsLen += len(element)
76+
}
77+
return colorCharsLen
4678
}

pre-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
gofmt -w .
44

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

0 commit comments

Comments
 (0)