Added webapp Dashboard + logic to interact with server.
[src/xds/xds-agent.git] / main.go
1 // TODO add Doc
2 //
3 package main
4
5 import (
6         "os"
7
8         "github.com/Sirupsen/logrus"
9         "github.com/codegangsta/cli"
10         "github.com/iotbzh/xds-agent/lib/agent"
11         "github.com/iotbzh/xds-agent/lib/xdsconfig"
12 )
13
14 const (
15         appName        = "xds-agent"
16         appDescription = "X(cross) Development System Agent is a web server that allows to remotely cross build applications."
17         appCopyright   = "Apache-2.0"
18         appUsage       = "X(cross) Development System Agent"
19 )
20
21 var appAuthors = []cli.Author{
22         cli.Author{Name: "Sebastien Douheret", Email: "sebastien@iot.bzh"},
23 }
24
25 // AppVersion is the version of this application
26 var AppVersion = "?.?.?"
27
28 // AppSubVersion is the git tag id added to version string
29 // Should be set by compilation -ldflags "-X main.AppSubVersion=xxx"
30 var AppSubVersion = "unknown-dev"
31
32 // xdsAgent main routine
33 func xdsAgent(cliCtx *cli.Context) error {
34         var err error
35
36         // Create Agent context
37         ctxAgent := agent.NewAgent(cliCtx)
38
39         // Load config
40         ctxAgent.Config, err = xdsconfig.Init(cliCtx, ctxAgent.Log)
41         if err != nil {
42                 return cli.NewExitError(err, 2)
43         }
44
45         // Run Agent (main loop)
46         errCode, err := ctxAgent.Run()
47
48         return cli.NewExitError(err, errCode)
49 }
50
51 // main
52 func main() {
53
54         // Create a new instance of the logger
55         log := logrus.New()
56
57         // Create a new App instance
58         app := cli.NewApp()
59         app.Name = appName
60         app.Description = appDescription
61         app.Usage = appUsage
62         app.Version = AppVersion + " (" + AppSubVersion + ")"
63         app.Authors = appAuthors
64         app.Copyright = appCopyright
65         app.Metadata = make(map[string]interface{})
66         app.Metadata["version"] = AppVersion
67         app.Metadata["git-tag"] = AppSubVersion
68         app.Metadata["logger"] = log
69
70         app.Flags = []cli.Flag{
71                 cli.StringFlag{
72                         Name:   "config, c",
73                         Usage:  "JSON config file to use\n\t",
74                         EnvVar: "XDS_CONFIGFILE",
75                 },
76                 cli.StringFlag{
77                         Name:   "log, l",
78                         Value:  "error",
79                         Usage:  "logging level (supported levels: panic, fatal, error, warn, info, debug)\n\t",
80                         EnvVar: "XDS_LOGLEVEL",
81                 },
82                 cli.StringFlag{
83                         Name:   "logfile",
84                         Value:  "stdout",
85                         Usage:  "filename where logs will be redirected (default stdout)\n\t",
86                         EnvVar: "XDS_LOGFILE",
87                 },
88         }
89
90         // only one action
91         app.Action = xdsAgent
92
93         app.Run(os.Args)
94 }