786e3699acb659cf08e98fc3d6f188580aae3c38
- Author
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Committer
- Ayman Bagabas <ayman.bagabas@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/cmd/soft/main.go b/cmd/soft/main.go
2index bb0954136e17dcc8628417098098f60677dc683a..160e9c73a153052b16d9fc2d255b62cc542b45aa 100644
3--- a/cmd/soft/main.go
4+++ b/cmd/soft/main.go
5@@ -2,16 +2,19 @@ package main
6
7 import (
8 "context"
9- "flag"
10 "fmt"
11 "log"
12 "os"
13 "os/signal"
14+ "runtime/debug"
15 "syscall"
16 "time"
17
18 "github.com/charmbracelet/soft-serve/config"
19 "github.com/charmbracelet/soft-serve/server"
20+ mcobra "github.com/muesli/mango-cobra"
21+ "github.com/muesli/roff"
22+ "github.com/spf13/cobra"
23 )
24
25 var (
26@@ -23,53 +26,85 @@ var (
27 // against. It's set via ldflags when building.
28 CommitSHA = ""
29
30- version = flag.Bool("version", false, "display version")
31-)
32-
33-func main() {
34- flag.Usage = func() {
35- fmt.Fprintf(os.Stderr, "Soft Serve, a self-hostable Git server for the command line.\n\n")
36- flag.PrintDefaults()
37+ rootCmd = &cobra.Command{
38+ Use: "soft",
39+ Short: "A self-hostable Git server for the command line",
40+ Long: "Soft Serve is a self-hostable Git server for the command line.",
41+ RunE: func(cmd *cobra.Command, args []string) error {
42+ return cmd.Help()
43+ },
44 }
45
46- flag.Parse()
47+ serveCmd = &cobra.Command{
48+ Use: "serve",
49+ Short: "Start the server",
50+ Long: "Start the server",
51+ Args: cobra.NoArgs,
52+ RunE: func(cmd *cobra.Command, args []string) error {
53+ cfg := config.DefaultConfig()
54+ s := server.NewServer(cfg)
55
56- if *version {
57- if len(CommitSHA) > 7 {
58- CommitSHA = CommitSHA[:7]
59- }
60- if Version == "" {
61- Version = "(built from source)"
62- }
63+ done := make(chan os.Signal, 1)
64+ signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
65
66- fmt.Printf("Soft Serve %s", Version)
67- if len(CommitSHA) > 0 {
68- fmt.Printf(" (%s)", CommitSHA)
69- }
70+ log.Printf("Starting SSH server on %s:%d", cfg.BindAddr, cfg.Port)
71+ go func() {
72+ if err := s.Start(); err != nil {
73+ log.Fatalln(err)
74+ }
75+ }()
76
77- fmt.Println()
78- os.Exit(0)
79+ <-done
80+
81+ log.Printf("Stopping SSH server on %s:%d", cfg.BindAddr, cfg.Port)
82+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
83+ defer func() { cancel() }()
84+ return s.Shutdown(ctx)
85+ },
86 }
87
88- cfg := config.DefaultConfig()
89- s := server.NewServer(cfg)
90+ manCmd = &cobra.Command{
91+ Use: "man",
92+ Short: "Generate man pages",
93+ Args: cobra.NoArgs,
94+ Hidden: true,
95+ RunE: func(cmd *cobra.Command, args []string) error {
96+ manPage, err := mcobra.NewManPage(1, rootCmd) //.
97+ if err != nil {
98+ return err
99+ }
100
101- done := make(chan os.Signal, 1)
102- signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
103+ manPage = manPage.WithSection("Copyright", "(C) 2021-2022 Charmbracelet, Inc.\n"+
104+ "Released under MIT license.")
105diff --git a/cmd/soft/man.go b/cmd/soft/man.go
106deleted file mode 100644
107index 1ddcd306a01d149f0e65dfcb559b22521c8dcfc1..0000000000000000000000000000000000000000
108--- a/cmd/soft/man.go
109+++ /dev/null
110@@ -1,25 +0,0 @@
111-//go:build mango
112-// +build mango
113-
114-package main
115-
116-import (
117- "flag"
118- "fmt"
119- "os"
120-
121- "github.com/muesli/mango"
122- "github.com/muesli/mango/mflag"
123- "github.com/muesli/roff"
124-)
125-
126-func init() {
127- manPage := mango.NewManPage(1, "soft", "A self-hostable Git server for the command line").
128- WithLongDescription("Soft Serve is a self-hostable Git server for the command line.").
129- WithSection("Copyright", "(C) 2021-2022 Charmbracelet, Inc.\n"+
130- "Released under MIT license.")
131-
132- flag.VisitAll(mflag.FlagVisitor(manPage))
133- fmt.Println(manPage.Build(roff.NewDocument()))
134- os.Exit(0)
135-}
136diff --git a/go.mod b/go.mod
137index a97f1892ada9f75ff55feb7159821e6b81e9b1a9..088bc2e6793f050084d73f210349365c9b2b56fa 100755
138--- a/go.mod
139+++ b/go.mod
140@@ -26,9 +26,9 @@ require (
141 github.com/gobwas/glob v0.2.3
142 github.com/gogs/git-module v1.6.1
143 github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
144- github.com/muesli/mango v0.1.0
145+ github.com/muesli/mango-cobra v1.2.0
146 github.com/muesli/roff v0.1.0
147- github.com/spf13/cobra v1.4.0
148+ github.com/spf13/cobra v1.5.0
149 gopkg.in/yaml.v3 v3.0.1
150 )
151
152@@ -56,6 +56,8 @@ require (
153 github.com/microcosm-cc/bluemonday v1.0.17 // indirect
154 github.com/mitchellh/go-homedir v1.1.0 // indirect
155 github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
156+ github.com/muesli/mango v0.1.0 // indirect
157+ github.com/muesli/mango-pflag v0.1.0 // indirect
158 github.com/olekukonko/tablewriter v0.0.5 // indirect
159 github.com/rivo/uniseg v0.2.0 // indirect
160 github.com/sahilm/fuzzy v0.1.0 // indirect
161diff --git a/go.sum b/go.sum
162index 629dced6623ca55149c5aeeb696b179fce673f84..a5d68d44bd3e096ed599fb98129367b28bb08514 100644
163--- a/go.sum
164+++ b/go.sum
165@@ -41,7 +41,7 @@ github.com/charmbracelet/wish v0.5.0/go.mod h1:5GAn5SrDSZ7cgKjnC+3kDmiIo7I6k4/AY
166 github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
167 github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
168 github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
169-github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
170+github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
171 github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
172 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
173 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
174@@ -122,6 +122,10 @@ github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 h1:kMlmsLSbjkikxQJ1IPw
175 github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
176 github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
177 github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
178+github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg=
179+github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA=
180+github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg=
181+github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0=
182 github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
183 github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
184 github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
185@@ -148,8 +152,8 @@ github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
186 github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
187 github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
188 github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
189-github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q=
190-github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
191+github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
192+github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
193 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
194 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
195 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=