This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
60 lines (47 loc) · 1.56 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
package main
import (
"fmt"
"os"
"github.com/blang/semver"
"github.com/spf13/pflag"
"code.storageos.net/storageos/c2-cli/apiclient"
"code.storageos.net/storageos/c2-cli/cmd"
"code.storageos.net/storageos/c2-cli/config"
"code.storageos.net/storageos/c2-cli/config/environment"
"code.storageos.net/storageos/c2-cli/config/file"
"code.storageos.net/storageos/c2-cli/config/flags"
)
// Version is the semantic version string which has been assigned to the
// cli application.
var Version string
func main() {
// Determine the cli app version from the embedded semver.
// If it errors 0.0.0 is returned
version, _ := semver.Make(Version)
// Initialise the configuration provider stack:
//
// → flags first. note we init the flagset here because it needs to be
// given to the InitCommand call (setting up global flags)
globalFlags := pflag.NewFlagSet("storageos", pflag.ContinueOnError)
// flags > envs > config file > default
defaultProvider := config.NewDefaulter()
fileProvider := file.NewProvider(defaultProvider)
envProvider := environment.NewProvider(fileProvider)
configProvider := flags.NewProvider(globalFlags, envProvider)
fileProvider.SetConfigProvider(configProvider)
client := apiclient.New()
app := cmd.InitCommand(
client,
configProvider,
globalFlags,
version,
)
if err := app.Execute(); err != nil {
// Attempt to map err to a command error.
err = cmd.MapCommandError(err)
// Get the appropriate exit code for the error.
code := cmd.ExitCodeForError(err)
fmt.Fprintf(app.OutOrStderr(), "Error: %v\n", err)
os.Exit(code)
}
}