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