/
main.go
112 lines (92 loc) · 2.8 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright 2018, CS Systemes d'Information, http://www.c-s.fr
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"fmt"
"os"
"sort"
log "github.com/sirupsen/logrus"
cli "github.com/urfave/cli"
"github.com/CS-SI/SafeScale/broker/cli/broker/cmd"
"github.com/CS-SI/SafeScale/broker/utils"
)
func main() {
app := cli.NewApp()
app.Name = "broker"
app.Usage = "broker COMMAND"
app.Version = VERSION + "-" + BUILD_DATE
app.Authors = []cli.Author{
cli.Author{
Name: "CS-SI",
Email: "safescale@c-s.fr",
},
}
app.EnableBashCompletion = true
cli.VersionFlag = cli.BoolFlag{
Name: "version, V",
Usage: "Print program version",
}
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "verbose, v",
Usage: "Increase verbosity",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "Show debug information",
},
// cli.IntFlag{
// Name: "port, p",
// Usage: "Bind to specified port `PORT`",
// Value: 50051,
// },
}
app.Before = func(c *cli.Context) error {
log.SetLevel(log.WarnLevel)
if c.GlobalBool("verbose") {
log.SetLevel(log.InfoLevel)
utils.Verbose = true
}
if c.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
utils.Debug = true
}
return nil
}
app.Commands = append(app.Commands, cmd.NetworkCmd)
sort.Sort(cli.CommandsByName(cmd.NetworkCmd.Subcommands))
app.Commands = append(app.Commands, cmd.TenantCmd)
sort.Sort(cli.CommandsByName(cmd.TenantCmd.Subcommands))
app.Commands = append(app.Commands, cmd.HostCmd)
sort.Sort(cli.CommandsByName(cmd.HostCmd.Subcommands))
app.Commands = append(app.Commands, cmd.VolumeCmd)
sort.Sort(cli.CommandsByName(cmd.VolumeCmd.Subcommands))
app.Commands = append(app.Commands, cmd.SSHCmd)
sort.Sort(cli.CommandsByName(cmd.SSHCmd.Subcommands))
app.Commands = append(app.Commands, cmd.BucketCmd)
sort.Sort(cli.CommandsByName(cmd.BucketCmd.Subcommands))
app.Commands = append(app.Commands, cmd.ShareCmd)
sort.Sort(cli.CommandsByName(cmd.ShareCmd.Subcommands))
app.Commands = append(app.Commands, cmd.ImageCmd)
sort.Sort(cli.CommandsByName(cmd.ImageCmd.Subcommands))
app.Commands = append(app.Commands, cmd.TemplateCmd)
sort.Sort(cli.CommandsByName(cmd.TemplateCmd.Subcommands))
sort.Sort(cli.CommandsByName(app.Commands))
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
}
}