Check dependency tools before running tests
[src/xds/xds-server.git] / main.go
1 /*
2  * Copyright (C) 2017-2018 "IoT.bzh"
3  * Author Sebastien Douheret <sebastien@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *
18  * xds-server: X(cross) Development System server.
19  */
20
21 package main
22
23 import (
24         "fmt"
25         "os"
26
27         "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xdsconfig"
28         "gerrit.automotivelinux.org/gerrit/src/xds/xds-server/lib/xdsserver"
29         "github.com/Sirupsen/logrus"
30         "github.com/codegangsta/cli"
31 )
32
33 const (
34         appName        = "xds-server"
35         appDescription = "X(cross) Development System Server is a web server that allows to remotely cross build applications."
36         appCopyright   = "Copyright (C) 2017-2018 IoT.bzh - Apache-2.0"
37         appUsage       = "X(cross) Development System Server"
38 )
39
40 var appAuthors = []cli.Author{
41         cli.Author{Name: "Sebastien Douheret", Email: "sebastien@iot.bzh"},
42 }
43
44 // AppVersion is the version of this application
45 var AppVersion = "?.?.?"
46
47 // AppSubVersion is the git tag id added to version string
48 // Should be set by compilation -ldflags "-X main.AppSubVersion=xxx"
49 var AppSubVersion = "unknown-dev"
50
51 // XDS Server application main routine
52 func xdsApp(cliCtx *cli.Context) error {
53         var err error
54
55         // Create XDS server context
56         ctxSvr := xdsserver.NewXdsServer(cliCtx)
57
58         // Load config
59         ctxSvr.Config, err = xdsconfig.Init(cliCtx, ctxSvr.Log)
60         if err != nil {
61                 return cli.NewExitError(err, -2)
62         }
63
64         // Run XDS Server (main loop)
65         errCode, err := ctxSvr.Run()
66
67         return cli.NewExitError(err, errCode)
68 }
69
70 // main
71 func main() {
72
73         // Create a new instance of the logger
74         log := logrus.New()
75
76         // Create a new App instance
77         app := cli.NewApp()
78         app.Name = appName
79         app.Description = appDescription
80         app.Usage = appUsage
81         app.Version = AppVersion + " (" + AppSubVersion + ")"
82         app.Authors = appAuthors
83         app.Copyright = appCopyright
84         app.Metadata = make(map[string]interface{})
85         app.Metadata["version"] = AppVersion
86         app.Metadata["git-tag"] = AppSubVersion
87         app.Metadata["logger"] = log
88
89         app.Flags = []cli.Flag{
90                 cli.StringFlag{
91                         Name:   "config, c",
92                         Usage:  "JSON config file to use\n\t",
93                         EnvVar: "APP_CONFIG",
94                 },
95                 cli.StringFlag{
96                         Name:   "log, l",
97                         Value:  "error",
98                         Usage:  "logging level (supported levels: panic, fatal, error, warn, info, debug)\n\t",
99                         EnvVar: "LOG_LEVEL",
100                 },
101                 cli.StringFlag{
102                         Name:   "logfile",
103                         Value:  "stdout",
104                         Usage:  "filename where logs will be redirected (default stdout)\n\t",
105                         EnvVar: "LOG_FILENAME",
106                 },
107                 cli.BoolFlag{
108                         Name:   "no-folderconfig, nfc",
109                         Usage:  fmt.Sprintf("Do not read folder config file (%s)\n\t", xdsconfig.FoldersConfigFilename),
110                         EnvVar: "NO_FOLDERCONFIG",
111                 },
112         }
113
114         // only one action: Web Server
115         app.Action = xdsApp
116
117         app.Run(os.Args)
118 }