48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"sort"
|
|
|
|
"github.com/gorilla/securecookie"
|
|
)
|
|
|
|
var (
|
|
fs = flag.NewFlagSet("gistea", flag.ExitOnError)
|
|
|
|
// Optional
|
|
_ = fs.String("config", "", "Config file")
|
|
jsonFlag = fs.Bool("json", false, "Enable JSON logging")
|
|
portFlag = fs.Int("port", 8080, "Port to run on")
|
|
sessionSecretFlag = fs.String("session-secret", string(securecookie.GenerateRandomKey(32)), "Session secret")
|
|
|
|
// Required
|
|
domainFlag = fs.String("domain", "", "Domain Invitea is running on")
|
|
giteaURLFlag = fs.String("gitea.url", "", "Gitea URL")
|
|
giteaClientKeyFlag = fs.String("gitea.client-key", "", "Gitea OAuth2 Client Key")
|
|
giteaClientSecretFlag = fs.String("gitea.client-secret", "", "Gitea OAuth2 Client Secret")
|
|
)
|
|
|
|
func requiredFlags() error {
|
|
required := map[string]*string{
|
|
"domain": domainFlag,
|
|
"gitea.url": giteaURLFlag,
|
|
"gitea.client-key": giteaClientKeyFlag,
|
|
"gitea.client-secret": giteaClientSecretFlag,
|
|
}
|
|
|
|
var unset []string
|
|
for k, v := range required {
|
|
if *v == "" {
|
|
unset = append(unset, k)
|
|
}
|
|
}
|
|
if len(unset) > 0 {
|
|
sort.Strings(unset)
|
|
return fmt.Errorf("the following flags were unset, but are required: %v", unset)
|
|
}
|
|
|
|
return nil
|
|
}
|