1package main23import (4 "context"5 "os"6 "runtime/debug"78 "github.com/charmbracelet/log/v2"9 "github.com/charmbracelet/soft-serve/cmd/soft/admin"10 "github.com/charmbracelet/soft-serve/cmd/soft/hook"11 "github.com/charmbracelet/soft-serve/cmd/soft/serve"12 "github.com/charmbracelet/soft-serve/pkg/config"13 logr "github.com/charmbracelet/soft-serve/pkg/log"14 "github.com/charmbracelet/soft-serve/pkg/version"15 "github.com/spf13/cobra"16 "go.uber.org/automaxprocs/maxprocs"17)1819var (20 // Version contains the application version number. It's set via ldflags21 // when building.22 Version = ""2324 // CommitSHA contains the SHA of the commit that this application was built25 // against. It's set via ldflags when building.26 CommitSHA = ""2728 // CommitDate contains the date of the commit that this application was29 // built against. It's set via ldflags when building.30 CommitDate = ""3132 rootCmd = &cobra.Command{33 Use: "soft",34 Short: "A self-hostable Git server for the command line",35 Long: "Soft Serve is a self-hostable Git server for the command line.",36 SilenceUsage: true,37 }38)3940func init() {41 rootCmd.AddCommand(42 serve.Command,43 hook.Command,44 admin.Command,45 )46 rootCmd.CompletionOptions.HiddenDefaultCmd = true4748 if len(CommitSHA) >= 7 {49 vt := rootCmd.VersionTemplate()50 rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA[0:7] + ")\n")51 }52 if Version == "" {53 if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {54 Version = info.Main.Version55 } else {56 Version = "unknown (built from source)"57 }58 }59 rootCmd.Version = Version6061 version.Version = Version62 version.CommitSHA = CommitSHA63 version.CommitDate = CommitDate64}6566func main() {67 ctx := context.Background()68 cfg := config.DefaultConfig()69 if cfg.Exist() {70 if err := cfg.Parse(); err != nil {71 log.Fatal(err)72 }73 }7475 if err := cfg.ParseEnv(); err != nil {76 log.Fatal(err)77 }7879 ctx = config.WithContext(ctx, cfg)80 logger, f, err := logr.NewLogger(cfg)81 if err != nil {82 log.Errorf("failed to create logger: %v", err)83 }8485 ctx = log.WithContext(ctx, logger)86 if f != nil {87 defer f.Close() // nolint: errcheck88 }8990 // Set global logger91 log.SetDefault(logger)9293 var opts []maxprocs.Option94 if config.IsVerbose() {95 opts = append(opts, maxprocs.Logger(log.Debugf))96 }9798 // Set the max number of processes to the number of CPUs99 // This is useful when running soft serve in a container100 if _, err := maxprocs.Set(opts...); err != nil {101 log.Warn("couldn't set automaxprocs", "error", err)102 }103104 if err := rootCmd.ExecuteContext(ctx); err != nil {105 os.Exit(1)106 }107}