This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
79 lines (61 loc) · 2.29 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
package main
import (
"fmt"
"os"
"runtime"
"strings"
"github.com/skatteetaten/ao/pkg/config"
"github.com/skatteetaten/ao/cmd"
"github.com/spf13/cobra"
)
const (
helpTemplate = `{{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}}{{end}}
Usage:
{{.UseLine}}{{if gt (len .Aliases) 0}}
Aliases:
{{.NameAndAliases}}{{end}}{{if .HasExample}}
Examples:
{{.Example}}{{end}}{{if hasSubCommandsAnnotation . "actions"}}
OpenShift Action Commands:{{range .Commands}}{{if eq (index .Annotations "type") "actions"}}
{{rpad .NameAndAliases .UsagePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if hasSubCommandsAnnotation . "remote"}}
Remote AuroraConfig Commands:{{range .Commands}}{{if eq (index .Annotations "type") "remote"}}
{{rpad .NameAndAliases .UsagePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if hasSubCommandsAnnotation . "development"}}
Local Development Commands:{{range .Commands}}{{if eq (index .Annotations "type") "development"}}
{{rpad .NameAndAliases .UsagePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if hasSubCommandsAnnotation . "local"}}
Local File Commands:{{range .Commands}}{{if eq (index .Annotations "type") "local"}}
{{rpad .NameAndAliases .UsagePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
Commands:{{range .Commands}}{{if (and (eq (index .Annotations "type") "") .IsAvailableCommand)}}
{{rpad .NameAndAliases .UsagePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
Flags:
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableSubCommands}}
Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}
`
)
func main() {
if runtime.GOOS == "windows" {
if len(os.Args) == 1 {
if strings.Contains(os.Args[0], "\\") {
// We presume we have been called from a double click since
// there are no arguments and the executable contains a catalog name.
config.Install("", false)
os.Exit(0)
}
}
}
cmd.RootCmd.SetHelpTemplate(helpTemplate)
if err := cmd.RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
cobra.AddTemplateFunc("hasSubCommandsAnnotation", func(cmd cobra.Command, annotation string) bool {
for _, c := range cmd.Commands() {
t := c.Annotations["type"]
if t == annotation {
return true
}
}
return false
})
}