1package main
 2
 3import (
 4	"runtime/debug"
 5
 6	"github.com/charmbracelet/log"
 7	_ "github.com/charmbracelet/soft-serve/log"
 8	"github.com/spf13/cobra"
 9)
10
11var (
12	// Version contains the application version number. It's set via ldflags
13	// when building.
14	Version = ""
15
16	// CommitSHA contains the SHA of the commit that this application was built
17	// against. It's set via ldflags when building.
18	CommitSHA = ""
19
20	rootCmd = &cobra.Command{
21		Use:   "soft",
22		Short: "A self-hostable Git server for the command line",
23		Long:  "Soft Serve is a self-hostable Git server for the command line.",
24		RunE: func(cmd *cobra.Command, args []string) error {
25			return cmd.Help()
26		},
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	if err := rootCmd.Execute(); err != nil {
55		log.Fatal(err)
56	}
57}