package config import ( "encoding/json" "flag" "fmt" "os" ) type BaseConfig struct { ProjectsDirectory string `json:"projects_directory"` Env string `json:"env"` StaticImages string `json:"static_images"` PublicImages string `json:"public_images"` PhpConf string `json:"php_conf"` Exports string `json:"exports"` Logs string `json:"logs"` PreviewPath string `json:"preview_path"` DataWww string `json:"data_www"` NginxConf string `json:"nginx_conf"` AdminURL string `json:"admin_url"` PreviewURL string `json:"preview_url"` AppImage string `json:"app_image"` WebserverImage string `json:"webserver_image"` EmptyDB string `json:"empty_db"` DB string `json:"db"` EmptyImages string `json:"empty_imaages"` DeploymentType string `json:"deployment_type"` DeploymentFile string `json:"deployment_file"` Port int `json:"port"` } func ReadBaseConfig(path string) (BaseConfig, error) { deploymentType := os.Getenv("DEPLOYMENT_TYPE") deploymentFile := flag.String("deployment-file", "", "path to config file") helpFlag := flag.Bool("help", false, "show help") flag.Parse() if *helpFlag { fmt.Println("Usage: infctl-cli --deployment-file=") fmt.Println("DEPLOYMENT_TYPE environment variable must be set to 'json' or 'api (api is not implemented yet)'") os.Exit(0) } var config BaseConfig if *deploymentFile != "" { config.DeploymentFile = *deploymentFile } data, err := os.ReadFile(path) if err != nil { return BaseConfig{}, fmt.Errorf("failed to read file: %w", err) } if err := json.Unmarshal(data, &config); err != nil { return BaseConfig{}, fmt.Errorf("failed to unmarshal JSON: %w", err) } config.DeploymentType = deploymentType return config, nil }