1package main
2
3import (
4 "context"
5 "os"
6 "runtime/debug"
7
8 "github.com/charmbracelet/log"
9 _ "github.com/charmbracelet/soft-serve/internal/init" // initialize registry
10 . "github.com/charmbracelet/soft-serve/internal/log"
11 "github.com/spf13/cobra"
12 "go.uber.org/automaxprocs/maxprocs"
13)
14
15var (
16 // Version contains the application version number. It's set via ldflags
17 // when building.
18 Version = ""
19
20 // CommitSHA contains the SHA of the commit that this application was built
21 // against. It's set via ldflags when building.
22 CommitSHA = ""
23
24 rootCmd = &cobra.Command{
25 Use: "soft",
26 Short: "A self-hostable Git server for the command line",
27 Long: "Soft Serve is a self-hostable Git server for the command line.",
28 SilenceUsage: true,
29 }
30)
31
32func init() {
33 rootCmd.AddCommand(
34 serveCmd,
35 manCmd,
36 hookCmd,
37 migrateConfig,
38 )
39 rootCmd.CompletionOptions.HiddenDefaultCmd = true
40
41 if len(CommitSHA) >= 7 {
42 vt := rootCmd.VersionTemplate()
43 rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA[0:7] + ")\n")
44 }
45 if Version == "" {
46 if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
47 Version = info.Main.Version
48 } else {
49 Version = "unknown (built from source)"
50 }
51 }
52 rootCmd.Version = Version
53}
54
55func main() {
56 logger := NewDefaultLogger()
57
58 // Set global logger
59 log.SetDefault(logger)
60
61 // Set the max number of processes to the number of CPUs
62 // This is useful when running soft serve in a container
63 if _, err := maxprocs.Set(maxprocs.Logger(logger.Debugf)); err != nil {
64 logger.Warn("couldn't set automaxprocs", "error", err)
65 }
66
67 ctx := log.WithContext(context.Background(), logger)
68 if err := rootCmd.ExecuteContext(ctx); err != nil {
69 os.Exit(1)
70 }
71}