2024-03-29 09:07:17 +01:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CliArgs struct {
|
2024-03-29 09:16:41 +01:00
|
|
|
DBName string
|
2024-03-29 09:07:17 +01:00
|
|
|
KeyFile string
|
|
|
|
LogFile string
|
|
|
|
PicsDir string
|
|
|
|
WebDir string
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandleCliArgs() (*CliArgs, error) {
|
|
|
|
var err error
|
|
|
|
cliArgs := new(CliArgs)
|
|
|
|
|
|
|
|
keyFile := flag.String("key", "/var/www/cpolis.key", "key file")
|
|
|
|
logFile := flag.String("log", "/var/log/cpolis.log", "log file")
|
|
|
|
picsDir := flag.String("pics", "/var/www/cpolis/pics", "pictures directory")
|
|
|
|
webDir := flag.String("web", "/var/www/cpolis/web", "web directory")
|
2024-03-29 09:16:41 +01:00
|
|
|
flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name")
|
2024-03-29 09:07:17 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
cliArgs.KeyFile, err = filepath.Abs(*keyFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error finding KeyFile: %v", err)
|
|
|
|
}
|
|
|
|
cliArgs.LogFile, err = filepath.Abs(*logFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error finding LogFile: %v", err)
|
|
|
|
}
|
|
|
|
cliArgs.PicsDir, err = filepath.Abs(*picsDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error finding PicsDir: %v", err)
|
|
|
|
}
|
|
|
|
cliArgs.WebDir, err = filepath.Abs(*webDir)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error finding WebDir: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cliArgs, nil
|
|
|
|
}
|