root.go

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