-
Notifications
You must be signed in to change notification settings - Fork 0
/
coverage.go
64 lines (52 loc) · 1.37 KB
/
coverage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"os"
"path/filepath"
"github.com/aabizri/navitia"
"github.com/aabizri/navitia/pretty"
"github.com/aabizri/transit/maps"
"github.com/fogleman/gg"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
var coverageCommand = cli.Command{
Name: "coverage",
Aliases: []string{"c"},
Usage: "List coverage",
Action: coverageAction,
}
func coverageAction(c *cli.Context) error {
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
defer cancel()
req := navitia.RegionRequest{
Geo: true,
}
res, err := session.Regions(ctx, req)
if err != nil {
return errors.Wrap(err, "coverageAction: error while retrieving list of regions")
}
err = pretty.DefaultRegionResultsConf.PrettyWrite(res, os.Stdout)
if err != nil {
return errors.Wrap(err, "error while pretty-printing")
}
// If enabled, draw !
if path := c.GlobalString("map"); path != "" {
if !filepath.IsAbs(path) {
wd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "couldn't retrieve working directory, consider giving an absolute path")
}
path = filepath.Join(wd, path)
}
img, err := maps.DrawRegions(res.Regions)
if err != nil {
return errors.Wrap(err, "error while drawing places")
}
err = gg.SavePNG(path, img)
if err != nil {
return errors.Wrapf(err, "error while saving image to %s", path)
}
}
return nil
}