-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
166 lines (129 loc) · 5.02 KB
/
config.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package main
import (
"fmt"
"os"
"path"
"regexp"
"strings"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)
var (
Verbose bool
)
func intro() {
fmt.Print(`
Ghashboard is a tool for creating a Github Actions dashboard full of badges.
The dashboard page is static and can be a Github README.md file.
If you include private repos, the page should be hosted on Github (or your badges will get 404ed).
The badge images will update automatically (by Github).
Example usage:
ghashboard --owners=owner1,owner2 --repos=repo1,repo2 --private=true --output=dashboard.md
For detailed usage:
ghashboard --help
`)
}
func usage(f *pflag.FlagSet) {
fmt.Printf("Usage: %s [options] [file]\n", path.Base(os.Args[0]))
fmt.Printf("\n")
fmt.Printf("Create a Github Actions dashboard full of badges\n")
fmt.Printf("\n")
fmt.Printf("%s\n", f.FlagUsages())
fmt.Printf("\n")
fmt.Printf(" options can also be set via environment variables\n")
fmt.Printf(" set GITHUB_TOKEN to use a personal access token and avoid rate limit errors.\n")
fmt.Printf("\n")
fmt.Printf(" external badges:\n")
for key, value := range getBuiltins() {
fmt.Printf(" %s - %s\n", key, value)
}
fmt.Printf("\n")
}
func initConfig(args []string) {
f := pflag.NewFlagSet("config", pflag.ExitOnError)
help := f.Bool("help", false, "Show help")
f.MarkHidden("help")
versionFlag := f.Bool("version", false, "Show version information")
f.String("log-level", "warn", "Log level [ debug | info | warn | error ]")
viper.BindPFlag("log-level", f.Lookup("log-level"))
viper.BindEnv("log-level", "LOG_LEVEL", "INPUT_LOG-LEVEL", "INPUT_LOG_LEVEL")
/*
* flags to build the repo list
*/
f.String("owners", "", "Owners")
viper.BindPFlag("owners", f.Lookup("owners"))
viper.BindEnv("owners", "OWNERS", "INPUT_OWNERS")
f.String("repos", "", "Repositories")
viper.BindPFlag("repos", f.Lookup("repos"))
viper.BindEnv("repos", "REPOS", "INPUT_REPOS")
f.String("skip", "", "Repositories to skip")
viper.BindPFlag("skip", f.Lookup("skip"))
viper.BindEnv("skip", "SKIP", "INPUT_SKIP")
// deliberately no flag because security
viper.BindEnv("github-token", "INPUT_TOKEN", "GITHUB_TOKEN")
/*
* flags for filtering the list
*/
f.Bool("empty", false, "Include repos with no eligible workflows")
viper.BindPFlag("empty", f.Lookup("empty"))
viper.BindEnv("empty", "EMPTY", "INPUT_EMPTY")
f.Bool("private", false, "Include private repos")
viper.BindPFlag("private", f.Lookup("private"))
viper.BindEnv("private", "PRIVATE", "INPUT_PRIVATE")
f.Bool("public", true, "Include public repos")
viper.BindPFlag("public", f.Lookup("public"))
viper.BindEnv("public", "PUBLIC", "INPUT_PUBLIC")
f.Bool("forks", false, "Include forks")
viper.BindPFlag("forks", f.Lookup("forks"))
viper.BindEnv("forks", "FORKS", "INPUT_FORKS")
f.Bool("archived", false, "Include archived repos")
viper.BindPFlag("archived", f.Lookup("archived"))
viper.BindEnv("archived", "ARCHIVED", "INPUT_ARCHIVED")
f.Bool("inactive", false, "Include inactive workflows")
viper.BindPFlag("inactive", f.Lookup("inactive"))
viper.BindEnv("inactive", "INACTIVE", "INPUT_INACTIVE")
f.String("include", "", "Actions to include")
viper.BindPFlag("include", f.Lookup("include"))
viper.BindEnv("include", "INCLUDE", "INPUT_INCLUDE")
f.String("exclude", "codeql,pages-build-deployment", "Actions to exclude")
viper.BindPFlag("exclude", f.Lookup("exclude"))
viper.BindEnv("exclude", "EXCLUDE", "INPUT_EXCLUDE")
/*
* flags to control the output
*/
f.String("externals", "", "External badges")
viper.BindPFlag("externals", f.Lookup("externals"))
viper.BindEnv("externals", "EXTERNALS", "INPUT_EXTERNALS")
f.String("title", "Github Actions Dashboard", "Title")
viper.BindPFlag("title", f.Lookup("title"))
viper.BindEnv("title", "TITLE", "INPUT_TITLE")
f.String("header", "<!-- NOTE: this file is generated by ghashboard. Do NOT edit by hand! -->", "Header")
viper.BindPFlag("header", f.Lookup("header"))
viper.BindEnv("header", "HEADER", "INPUT_HEADER")
f.String("footer", "<small>Built with <a href=\"https://github.com/fileformat/ghashboard\"><img src=\"https://ghashboard.marcuse.info/favicon.svg\" alt=\"Ghashboard logo\" height=\"16\" />ghashboard</a>!</small>", "Footer")
viper.BindPFlag("footer", f.Lookup("footer"))
viper.BindEnv("footer", "FOOTER", "INPUT_FOOTER")
f.String("format", "markdown", "Output format [ "+strings.Join(GetStandardTemplates(), " | ")+" | json ]")
viper.BindPFlag("format", f.Lookup("format"))
viper.BindEnv("format", "FORMAT", "INPUT_FORMAT")
f.String("output", "dashboard.md", "File name (or - for stdout)")
viper.BindPFlag("output", f.Lookup("output"))
viper.BindEnv("output", "OUTPUT", "INPUT_OUTPUT")
f.Parse(args)
if *versionFlag {
fmt.Printf("ghashboard v%s (%s built on %s by %s)\n", version, commit, date, builtBy)
os.Exit(0)
}
if *help {
usage(f)
os.Exit(0)
}
}
var arraySplitter = regexp.MustCompile(`[\s,]+`)
func viper_GetStringSlice(key string) []string {
str := viper.GetString(key)
if str == "" {
return []string{}
}
return arraySplitter.Split(str, -1)
}