1package main
2
3import (
4 "context"
5 "os"
6 "runtime/debug"
7
8 "github.com/charmbracelet/log"
9 . "github.com/charmbracelet/soft-serve/internal/log"
10 "github.com/spf13/cobra"
11)
12
13var (
14 // Version contains the application version number. It's set via ldflags
15 // when building.
16 Version = ""
17
18 // CommitSHA contains the SHA of the commit that this application was built
19 // against. It's set via ldflags when building.
20 CommitSHA = ""
21
22 rootCmd = &cobra.Command{
23 Use: "soft",
24 Short: "A self-hostable Git server for the command line",
25 Long: "Soft Serve is a self-hostable Git server for the command line.",
26 SilenceUsage: true,
27 }
28)
29
30func init() {
31 rootCmd.AddCommand(
32 serveCmd,
33 manCmd,
34 hookCmd,
35 migrateConfig,
36 )
37 rootCmd.CompletionOptions.HiddenDefaultCmd = true
38
39 if len(CommitSHA) >= 7 {
40 vt := rootCmd.VersionTemplate()
41 rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA[0:7] + ")\n")
42 }
43 if Version == "" {
44 if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
45 Version = info.Main.Version
46 } else {
47 Version = "unknown (built from source)"
48 }
49 }
50 rootCmd.Version = Version
51}
52
53func main() {
54 logger := NewDefaultLogger()
55 ctx := log.WithContext(context.Background(), logger)
56 if err := rootCmd.ExecuteContext(ctx); err != nil {
57 os.Exit(1)
58 }
59}