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