-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate man pages and completions
using mango-cobra
- Loading branch information
1 parent
5ae15b5
commit d128631
Showing
9 changed files
with
158 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,6 @@ cmd/soft/soft | |
.ssh | ||
.repos | ||
dist | ||
testdata | ||
testdata | ||
completions/ | ||
manpages/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
includes: | ||
- from_url: | ||
url: charmbracelet/meta/main/goreleaser.yaml | ||
url: charmbracelet/meta/main/goreleaser-full.yaml | ||
|
||
variables: | ||
main: "./cmd/soft" | ||
binary_name: soft | ||
description: "A tasty, self-hostable Git server for the command line🍦" | ||
github_url: "https://github.com/charmbracelet/soft-serve" | ||
maintainer: "Christian Rocha <christian@charm.sh>" | ||
brew_commit_author_name: "Christian Rocha" | ||
brew_commit_author_email: "christian@charm.sh" | ||
maintainer: "Ayman Bagabas <ayman@charm.sh>" | ||
brew_commit_author_name: "Ayman Bagabas" | ||
brew_commit_author_email: "ayman@charm.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
mcobra "github.com/muesli/mango-cobra" | ||
"github.com/muesli/roff" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
manCmd = &cobra.Command{ | ||
Use: "man", | ||
Short: "Generate man pages", | ||
Args: cobra.NoArgs, | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
manPage, err := mcobra.NewManPage(1, rootCmd) //. | ||
if err != nil { | ||
return err | ||
} | ||
|
||
manPage = manPage.WithSection("Copyright", "(C) 2021-2022 Charmbracelet, Inc.\n"+ | ||
"Released under MIT license.") | ||
fmt.Println(manPage.Build(roff.NewDocument())) | ||
return nil | ||
}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"runtime/debug" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
// Version contains the application version number. It's set via ldflags | ||
// when building. | ||
Version = "" | ||
|
||
// CommitSHA contains the SHA of the commit that this application was built | ||
// against. It's set via ldflags when building. | ||
CommitSHA = "" | ||
|
||
rootCmd = &cobra.Command{ | ||
Use: "soft", | ||
Short: "A self-hostable Git server for the command line", | ||
Long: "Soft Serve is a self-hostable Git server for the command line.", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return cmd.Help() | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand( | ||
serveCmd, | ||
manCmd, | ||
) | ||
rootCmd.CompletionOptions.HiddenDefaultCmd = true | ||
|
||
if len(CommitSHA) >= 7 { | ||
vt := rootCmd.VersionTemplate() | ||
rootCmd.SetVersionTemplate(vt[:len(vt)-1] + " (" + CommitSHA[0:7] + ")\n") | ||
} | ||
if Version == "" { | ||
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" { | ||
Version = info.Main.Version | ||
} else { | ||
Version = "unknown (built from source)" | ||
} | ||
} | ||
rootCmd.Version = Version | ||
} | ||
|
||
func main() { | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/charmbracelet/soft-serve/config" | ||
"github.com/charmbracelet/soft-serve/server" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
serveCmd = &cobra.Command{ | ||
Use: "serve", | ||
Short: "Start the server", | ||
Long: "Start the server", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
cfg := config.DefaultConfig() | ||
s := server.NewServer(cfg) | ||
|
||
done := make(chan os.Signal, 1) | ||
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
log.Printf("Starting SSH server on %s:%d", cfg.BindAddr, cfg.Port) | ||
go func() { | ||
if err := s.Start(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
}() | ||
|
||
<-done | ||
|
||
log.Printf("Stopping SSH server on %s:%d", cfg.BindAddr, cfg.Port) | ||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
defer func() { cancel() }() | ||
return s.Shutdown(ctx) | ||
}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters