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	)
36	rootCmd.CompletionOptions.HiddenDefaultCmd = true
37
38	if len(CommitSHA) >= 7 {
39		vt := rootCmd.VersionTemplate()
40		rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA[0:7] + ")\n")
41	}
42	if Version == "" {
43		if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
44			Version = info.Main.Version
45		} else {
46			Version = "unknown (built from source)"
47		}
48	}
49	rootCmd.Version = Version
50}
51
52func main() {
53	if err := rootCmd.Execute(); err != nil {
54		log.Fatal(err)
55	}
56}