package main import ( "errors" "fmt" "os" "alin.ovh/homestead/domain/content/builder" "alin.ovh/homestead/shared/config" "alin.ovh/homestead/shared/storage/files" "alin.ovh/homestead/shared/vcs" "alin.ovh/x/log" "github.com/ardanlabs/conf/v3" ) type Options struct { *builder.Options Destination string `conf:"default:./public,short:d,flag:dest"` Compress bool `conf:"default:true"` } const branch = "main" func main() { options := &Options{} if help, err := conf.Parse("", options); err != nil { if errors.Is(err, conf.ErrHelpWanted) { fmt.Println(help) os.Exit(1) } panic("error parsing configuration: " + err.Error()) } log := log.Configure(!options.Development) repo, _, err := vcs.CloneOrOpen(&vcs.Options{ LocalPath: options.Source, RemoteURL: options.VCSRemoteURL, Branch: branch, }, log.Named("vcs")) if err != nil { panic("could not open repository: " + err.Error()) } options.Repo = repo options.Storage, err = files.NewWriter( options.Destination, log.Named("storage"), &files.Options{ Compress: options.Compress, }, ) if err != nil { panic("could not create storage: " + err.Error()) } log.Debug("starting build process") cfg, err := config.GetConfig(options.Source, log) if err != nil { log.Error("could not read config", "error", err) } err = builder.BuildSite(options.Options, cfg, log) if err != nil { panic("could not build site: " + err.Error()) } }