Simplify config handling

* Switch to urfave/cli/v2
* Add more environment variables
This commit is contained in:
Manuel Rüger
2023-04-18 15:06:16 +02:00
parent d1f69bc704
commit 262853f6c0
7 changed files with 221 additions and 204 deletions

46
auth.go
View File

@@ -18,32 +18,23 @@ type Credentials struct {
}
func GetCredentials(
flags Flags,
config *Config,
username string,
password string,
targetURL string,
baseURL string,
compileOnly bool,
) (*Credentials, error) {
var err error
var (
username = flags.Username
password = flags.Password
targetURL = flags.TargetURL
)
if username == "" {
username = config.Username
}
if password == "" {
password = config.Password
if password == "" {
if !flags.CompileOnly {
return nil, errors.New(
"Confluence password should be specified using -p " +
"flag or be stored in configuration file",
)
}
password = "none"
if !compileOnly {
return nil, errors.New(
"confluence password should be specified using -p " +
"flag or be stored in configuration file",
)
}
password = "none"
}
if password == "-" {
@@ -58,7 +49,7 @@ func GetCredentials(
password = string(stdin)
}
if flags.CompileOnly && targetURL == "" {
if compileOnly && targetURL == "" {
targetURL = "http://localhost"
}
@@ -70,20 +61,15 @@ func GetCredentials(
)
}
baseURL := url.Scheme + "://" + url.Host
if url.Host == "" {
baseURL = flags.BaseURL
if baseURL == "" {
baseURL = config.BaseURL
}
if baseURL == "" {
return nil, errors.New(
"Confluence base URL should be specified using -l " +
"confluence base URL should be specified using -l " +
"flag or be stored in configuration file",
)
}
} else {
baseURL = url.Scheme + "://" + url.Host
}
baseURL = strings.TrimRight(baseURL, `/`)