forked from pivotal-cf/pivnet-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (48 loc) · 1.23 KB
/
main.go
File metadata and controls
58 lines (48 loc) · 1.23 KB
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
package main
import (
"fmt"
"os"
"github.com/jessevdk/go-flags"
"github.com/pivotal-cf/pivnet-cli/commands"
"github.com/pivotal-cf/pivnet-cli/errorhandler"
"github.com/pivotal-cf/pivnet-cli/version"
)
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)
}
}