1package main
2
3import (
4 "os"
5 "runtime/debug"
6
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 SilenceUsage: true,
25 }
26)
27
28func init() {
29 rootCmd.AddCommand(
30 serveCmd,
31 manCmd,
32 hookCmd,
33 migrateConfig,
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 os.Exit(1)
54 }
55}