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