diff options
Diffstat (limited to 'cmd/build/main.go')
-rw-r--r-- | cmd/build/main.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/cmd/build/main.go b/cmd/build/main.go new file mode 100644 index 0000000..9b6a79b --- /dev/null +++ b/cmd/build/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + "io/fs" + "log" + "log/slog" + "os" + + "github.com/BurntSushi/toml" + "github.com/ardanlabs/conf/v3" + "github.com/pkg/errors" +) + +func main() { + if os.Getenv("DEBUG") != "" { + slog.SetLogLoggerLevel(slog.LevelDebug) + } + slog.Debug("starting build process") + + ioConfig := IOConfig{} + if help, err := conf.Parse("", &ioConfig); err != nil { + if errors.Is(err, conf.ErrHelpWanted) { + fmt.Println(help) + os.Exit(1) + } + log.Panicf("parsing I/O configuration: %v", err) + } + + if ioConfig.Source != "." { + err := os.Chdir(ioConfig.Source) + if err != nil { + log.Panic("could not change to source directory") + } + } + + if err := buildSite(ioConfig); err != nil { + switch cause := errors.Cause(err).(type) { + case *fs.PathError: + slog.Info("pathError") + slog.Error(fmt.Sprintf("%s", err)) + case toml.ParseError: + slog.Info("parseError") + slog.Error(fmt.Sprintf("%s", err)) + default: + slog.Info("other") + slog.Error(fmt.Sprintf("cause:%+v", errors.Cause(cause))) + slog.Error(fmt.Sprintf("%+v", cause)) + } + os.Exit(1) + } +} |