package control import ( "flag" "fmt" "path/filepath" ) type CliArgs struct { DBName string KeyFile string LogFile string Port string PicsDir string RSSFile string WebDir string } func HandleCliArgs() (*CliArgs, error) { var err error cliArgs := new(CliArgs) keyFile := flag.String("key", "/var/www/cpolis/cpolis.key", "key file") logFile := flag.String("log", "/var/log/cpolis.log", "log file") picsDir := flag.String("pics", "/var/www/cpolis/pics", "pictures directory") cliArgs.Port = fmt.Sprint(":", flag.Int("port", 8080, "port")) rssFile := flag.String("rss", "/var/www/cpolis/cpolis.rss", "RSS file") webDir := flag.String("web", "/var/www/cpolis/web", "web directory") flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name") flag.Parse() cliArgs.KeyFile, err = filepath.Abs(*keyFile) if err != nil { return nil, fmt.Errorf("error finding absolute path for KeyFile: %v", err) } cliArgs.LogFile, err = filepath.Abs(*logFile) if err != nil { return nil, fmt.Errorf("error finding absolute path for LogFile: %v", err) } cliArgs.PicsDir, err = filepath.Abs(*picsDir) if err != nil { return nil, fmt.Errorf("error finding absolute path for PicsDir: %v", err) } cliArgs.RSSFile, err = filepath.Abs(*rssFile) if err != nil { return nil, fmt.Errorf("error finding absolute path for RSSFile: %v", err) } cliArgs.WebDir, err = filepath.Abs(*webDir) if err != nil { return nil, fmt.Errorf("error finding absolute path for WebDir: %v", err) } return cliArgs, nil }