This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
86 lines (73 loc) · 2.82 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
package main
import (
"fmt"
"net"
"os"
"github.com/concourse/fly/commands"
"github.com/concourse/fly/rc"
"github.com/concourse/fly/ui"
"github.com/concourse/go-concourse/concourse"
"github.com/concourse/skymarshal/provider"
"github.com/jessevdk/go-flags"
_ "github.com/concourse/skymarshal/basicauth"
_ "github.com/concourse/skymarshal/bitbucket/cloud"
_ "github.com/concourse/skymarshal/bitbucket/server"
_ "github.com/concourse/skymarshal/genericoauth"
_ "github.com/concourse/skymarshal/github"
_ "github.com/concourse/skymarshal/gitlab"
_ "github.com/concourse/skymarshal/noauth"
_ "github.com/concourse/skymarshal/uaa"
)
func main() {
parser := flags.NewParser(&commands.Fly, flags.HelpFlag|flags.PassDoubleDash)
parser.NamespaceDelimiter = "-"
groups := parser.Find("set-team").Groups()
var authGroup *flags.Group
for _, group := range groups {
if group.ShortDescription == "Authentication" {
authGroup = group
break
}
}
authConfigs := make(provider.AuthConfigs)
for name, p := range provider.GetProviders() {
authConfigs[name] = p.AddAuthGroup(authGroup)
}
commands.Fly.SetTeam.Auth.Configs = authConfigs
helpParser := flags.NewParser(&commands.Fly, flags.HelpFlag)
helpParser.NamespaceDelimiter = "-"
_, err := parser.Parse()
if err != nil {
if err == concourse.ErrUnauthorized {
fmt.Fprintln(ui.Stderr, "not authorized. run the following to log in:")
fmt.Fprintln(ui.Stderr, "")
fmt.Fprintln(ui.Stderr, " "+ui.Embolden("fly -t %s login", commands.Fly.Target))
fmt.Fprintln(ui.Stderr, "")
} else if err == rc.ErrNoTargetSpecified {
fmt.Fprintln(ui.Stderr, "no target specified. specify the target with "+ui.Embolden("-t")+" or log in like so:")
fmt.Fprintln(ui.Stderr, "")
fmt.Fprintln(ui.Stderr, " "+ui.Embolden("fly -t (alias) login -c (concourse url)"))
fmt.Fprintln(ui.Stderr, "")
} else if versionErr, ok := err.(rc.ErrVersionMismatch); ok {
fmt.Fprintln(ui.Stderr, versionErr.Error())
fmt.Fprintln(ui.Stderr, ui.WarningColor("cowardly refusing to run due to significant version discrepancy"))
} else if netErr, ok := err.(net.Error); ok {
fmt.Fprintf(ui.Stderr, "could not reach the Concourse server called %s:\n", ui.Embolden("%s", commands.Fly.Target))
fmt.Fprintln(ui.Stderr, "")
fmt.Fprintln(ui.Stderr, " "+ui.Embolden("%s", netErr))
fmt.Fprintln(ui.Stderr, "")
fmt.Fprintln(ui.Stderr, "is the targeted Concourse running? better go catch it lol")
} else if err == commands.ErrShowHelpMessage {
helpParser.ParseArgs([]string{"-h"})
helpParser.WriteHelp(os.Stdout)
os.Exit(0)
} else if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrCommandRequired {
helpParser.ParseArgs([]string{"-h"})
helpParser.WriteHelp(os.Stdout)
os.Exit(0)
} else {
fmt.Fprintf(ui.Stderr, "error: %s\n", err)
}
os.Exit(1)
}
}