-
Notifications
You must be signed in to change notification settings - Fork 27
/
main.go
77 lines (66 loc) · 1.95 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
package main
import (
"fmt"
"github.com/pivotal-cf/pivnet-cli/v3/rc"
"github.com/pivotal-cf/pivnet-cli/v3/rc/filesystem"
"os"
"github.com/jessevdk/go-flags"
"github.com/pivotal-cf/pivnet-cli/v3/commands"
"github.com/pivotal-cf/pivnet-cli/v3/errorhandler"
"github.com/pivotal-cf/pivnet-cli/v3/version"
"github.com/pivotal-cf/pivnet-cli/v3/hostwarning"
)
var (
// buildVersion is deliberately left uninitialized so it can be set at compile-time
buildVersion string
)
func main() {
if buildVersion == "" {
version.Version = "dev"
} else {
version.Version = buildVersion
}
parser := flags.NewParser(&commands.Pivnet, flags.HelpFlag)
if len(os.Args) > 1 && os.Args[1] == "manpage" {
parser.WriteManPage(os.Stdout)
return
}
_, err := parser.Parse()
if err != nil {
if err == commands.ErrShowHelpMessage {
helpParser := flags.NewParser(&commands.Pivnet, flags.HelpFlag)
helpParser.NamespaceDelimiter = "-"
_, _ = helpParser.ParseArgs([]string{"-h"})
helpParser.WriteHelp(os.Stdout)
os.Exit(0)
}
// Do not consider the built-in help an error
if e, ok := err.(*flags.Error); ok {
if e.Type == flags.ErrHelp {
fmt.Fprintln(os.Stdout, err.Error())
os.Exit(0)
}
}
if err == errorhandler.ErrAlreadyHandled {
os.Exit(1)
}
coloredMessage := fmt.Sprintf(errorhandler.RedFunc(err.Error()))
fmt.Fprintln(os.Stderr, coloredMessage)
os.Exit(1)
} else {
pivnetClient := commands.NewPivnetClient()
client := commands.NewPivnetVersionsClient(pivnetClient)
result := client.Warn(version.Version)
if result != "" {
fmt.Fprintf(os.Stderr, "\n%s\n", result)
}
rcFileReadWriter := filesystem.NewPivnetRCReadWriter(commands.Pivnet.ConfigFile)
rch := rc.NewRCHandler(rcFileReadWriter)
if commands.Pivnet.Profile != nil {
profile, err := rch.ProfileForName(commands.Pivnet.Profile.Name)
if err == nil && profile != nil {
fmt.Fprint(os.Stderr, hostwarning.NewHostWarning(profile.Host).Warn())
}
}
}
}