refactor: introduce config file
This commit is contained in:
parent
de39350aa5
commit
93f3ccd59d
44
main.go
44
main.go
@ -10,6 +10,15 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
PasswordCommand string
|
||||
PasswordCommandArgs []string
|
||||
User string
|
||||
DocspellURL string
|
||||
ArchiveDirectory string
|
||||
ImportDirectories []string
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("##################### START #####################")
|
||||
fmt.Println(" Docspell Consumedir Cleaner - v0.1 beta")
|
||||
@ -18,16 +27,19 @@ func main() {
|
||||
fmt.Println("#################################################")
|
||||
fmt.Println()
|
||||
|
||||
var cfg config
|
||||
// Get password from rbw
|
||||
cmd := exec.Command("rbw", "get", "Docspell")
|
||||
cmd := exec.Command(cfg.PasswordCommand, cfg.PasswordCommandArgs...)
|
||||
password, err := cmd.Output()
|
||||
if err != nil {
|
||||
fmt.Println("Error getting password:", err)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
validateConfig(cfg)
|
||||
|
||||
// Login
|
||||
loginCmd := exec.Command("dsc", "login", "--user", "jacob1123", "--password", strings.TrimSpace(string(password)))
|
||||
loginCmd := exec.Command("dsc", "login", "--user", cfg.User, "--password", strings.TrimSpace(string(password)))
|
||||
if err := loginCmd.Run(); err != nil {
|
||||
fmt.Println("Login failed:", err)
|
||||
os.Exit(0)
|
||||
@ -39,23 +51,13 @@ func main() {
|
||||
os.Exit(-4)
|
||||
}
|
||||
|
||||
dsUrl := "https://docs.javil.eu"
|
||||
dsUrl := cfg.DocspellURL
|
||||
|
||||
if len(os.Args) != 3 {
|
||||
fmt.Println("FATAL Exactly two parameters needed")
|
||||
os.Exit(-3)
|
||||
}
|
||||
|
||||
dsConsumedir := strings.TrimRight(os.Args[1], "/")
|
||||
dsArchivedir := strings.TrimRight(os.Args[2], "/")
|
||||
|
||||
if dsConsumedir == "" || dsArchivedir == "" {
|
||||
fmt.Println("FATAL Parameter missing")
|
||||
fmt.Printf(" ds_consumedir: %s\n", dsConsumedir)
|
||||
fmt.Printf(" ds_archivedir: %s\n", dsArchivedir)
|
||||
os.Exit(-2)
|
||||
}
|
||||
|
||||
fmt.Println("Settings:")
|
||||
uploadMissing := os.Getenv("DS_CC_UPLOAD_MISSING") == "true"
|
||||
if uploadMissing {
|
||||
@ -196,3 +198,19 @@ func main() {
|
||||
fmt.Println("################# DONE #################")
|
||||
fmt.Println(time.Now().Format(time.RFC1123))
|
||||
}
|
||||
|
||||
func validateConfig(cfg config) {
|
||||
if len(cfg.ImportDirectories) == 0 || cfg.ArchiveDirectory == "" {
|
||||
fmt.Println("FATAL Parameter missing")
|
||||
fmt.Printf(" import directories: %v\n", cfg.ImportDirectories)
|
||||
fmt.Printf(" archive directory: %s\n", cfg.ArchiveDirectory)
|
||||
os.Exit(-2)
|
||||
}
|
||||
|
||||
if cfg.User == "" {
|
||||
fmt.Println("FATAL User is missing")
|
||||
os.Exit(-3)
|
||||
}
|
||||
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user