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