2024-03-29 09:07:17 +01:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CliArgs struct {
|
2024-04-07 19:29:35 +02:00
|
|
|
Description string
|
|
|
|
DBName string
|
|
|
|
Domain string
|
|
|
|
KeyFile string
|
|
|
|
Link string
|
|
|
|
LogFile string
|
|
|
|
Port string
|
|
|
|
PicsDir string
|
|
|
|
RSSFile string
|
|
|
|
Title string
|
|
|
|
WebDir string
|
2024-03-29 09:07:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func HandleCliArgs() (*CliArgs, error) {
|
|
|
|
var err error
|
|
|
|
cliArgs := new(CliArgs)
|
|
|
|
|
2024-04-07 10:58:07 +02:00
|
|
|
flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name")
|
2024-04-07 19:29:35 +02:00
|
|
|
flag.StringVar(&cliArgs.Description, "desc", "Description", "Channel description")
|
2024-04-07 11:32:38 +02:00
|
|
|
flag.StringVar(&cliArgs.Domain, "domain", "", "domain name")
|
2024-03-30 09:55:37 +01:00
|
|
|
keyFile := flag.String("key", "/var/www/cpolis/cpolis.key", "key file")
|
2024-04-07 19:29:35 +02:00
|
|
|
flag.StringVar(&cliArgs.Link, "link", "Link", "Channel Link")
|
2024-03-29 09:07:17 +01:00
|
|
|
logFile := flag.String("log", "/var/log/cpolis.log", "log file")
|
2024-04-07 10:58:07 +02:00
|
|
|
flag.StringVar(&cliArgs.PicsDir, "pics", "pics", "pictures directory")
|
2024-03-30 10:22:51 +01:00
|
|
|
port := flag.Int("port", 8080, "port")
|
2024-03-30 09:55:37 +01:00
|
|
|
rssFile := flag.String("rss", "/var/www/cpolis/cpolis.rss", "RSS file")
|
2024-04-07 19:29:35 +02:00
|
|
|
flag.StringVar(&cliArgs.Title, "title", "Title", "Channel title")
|
2024-03-29 09:07:17 +01:00
|
|
|
webDir := flag.String("web", "/var/www/cpolis/web", "web directory")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
cliArgs.KeyFile, err = filepath.Abs(*keyFile)
|
|
|
|
if err != nil {
|
2024-03-29 09:48:03 +01:00
|
|
|
return nil, fmt.Errorf("error finding absolute path for KeyFile: %v", err)
|
2024-03-29 09:07:17 +01:00
|
|
|
}
|
2024-03-30 09:55:37 +01:00
|
|
|
|
2024-03-29 09:07:17 +01:00
|
|
|
cliArgs.LogFile, err = filepath.Abs(*logFile)
|
|
|
|
if err != nil {
|
2024-03-29 09:48:03 +01:00
|
|
|
return nil, fmt.Errorf("error finding absolute path for LogFile: %v", err)
|
2024-03-29 09:07:17 +01:00
|
|
|
}
|
2024-03-30 09:55:37 +01:00
|
|
|
|
2024-04-07 10:58:07 +02:00
|
|
|
_, err = filepath.Abs(cliArgs.PicsDir)
|
2024-03-29 09:07:17 +01:00
|
|
|
if err != nil {
|
2024-03-29 09:48:03 +01:00
|
|
|
return nil, fmt.Errorf("error finding absolute path for PicsDir: %v", err)
|
2024-03-29 09:07:17 +01:00
|
|
|
}
|
2024-03-30 09:55:37 +01:00
|
|
|
|
2024-03-30 10:22:51 +01:00
|
|
|
cliArgs.Port = fmt.Sprint(":", *port)
|
|
|
|
|
2024-03-30 09:55:37 +01:00
|
|
|
cliArgs.RSSFile, err = filepath.Abs(*rssFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error finding absolute path for RSSFile: %v", err)
|
|
|
|
}
|
|
|
|
|
2024-03-29 09:07:17 +01:00
|
|
|
cliArgs.WebDir, err = filepath.Abs(*webDir)
|
|
|
|
if err != nil {
|
2024-03-29 09:48:03 +01:00
|
|
|
return nil, fmt.Errorf("error finding absolute path for WebDir: %v", err)
|
2024-03-29 09:07:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return cliArgs, nil
|
|
|
|
}
|