-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (77 loc) · 1.75 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
travel is a command line tool for planning your travel between two places
*/
package main
import (
"fmt"
"net/http"
"os"
"time"
"github.com/aabizri/navitia"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
const standardRequestTimeout = 10 * time.Second
var commands = []cli.Command{
placeCommand,
journeyCommand,
coverageCommand,
}
var (
apiKey string
requestTimeout time.Duration
session *navitia.Session
)
var flags = []cli.Flag{
cli.StringFlag{
Name: "key",
Usage: "Api Key for navitia.io",
Destination: &apiKey,
EnvVar: "NAVITIA_TOKEN",
},
cli.DurationFlag{
Name: "req-timeout, rt",
Usage: "Request timeout value",
Value: standardRequestTimeout,
Destination: &requestTimeout,
},
cli.StringFlag{
Name: "in",
Usage: "Coverage to use [NOT IMPLEMENTED]",
},
cli.StringFlag{
Name: "map",
Usage: "Write a map to the specified path",
},
}
var authors = []cli.Author{
cli.Author{
Name: "Alexandre A. Bizri",
Email: "alexandre@bizri.fr",
},
}
const description = "transit is a tool for planning, monitoring and searching public transit information"
func establishSession(ctx *cli.Context) error {
if apiKey == "" {
return errors.Errorf("ERROR: No Api Key specified")
}
var err error
session, err = navitia.NewCustom(apiKey, "http://api.navitia.io/v1", &http.Client{})
return errors.Wrap(err, "Error while creating session")
}
func main() {
app := cli.NewApp()
app.Version = "-dev"
app.Description = description
app.Name = "transit"
app.Usage = "The public transit tool for the CLI"
app.Authors = authors
app.Before = establishSession
app.Flags = flags
app.Commands = commands
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}