From feb2aff49c74135d4b6e4f362b0516b12515a7ec Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Fri, 1 Mar 2024 17:30:16 -0500 Subject: [PATCH] cmd: add man generation command --- cmd/spicedb/main.go | 22 ++++++++++++++++++++++ go.mod | 4 ++++ go.sum | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/cmd/spicedb/main.go b/cmd/spicedb/main.go index a1ea2f2f87..c7495bb4de 100644 --- a/cmd/spicedb/main.go +++ b/cmd/spicedb/main.go @@ -2,8 +2,11 @@ package main import ( "errors" + "fmt" "os" + mcobra "github.com/muesli/mango-cobra" + "github.com/muesli/roff" "github.com/rs/zerolog" "github.com/sercand/kuberesolver/v5" "github.com/spf13/cobra" @@ -89,6 +92,25 @@ func main() { testingCmd := cmd.NewTestingCommand(rootCmd.Use, &testServerConfig) cmd.RegisterTestingFlags(testingCmd, &testServerConfig) rootCmd.AddCommand(testingCmd) + + rootCmd.AddCommand(&cobra.Command{ + Use: "man", + Short: "Generate the SpiceDB manpage", + SilenceUsage: true, + DisableFlagsInUseLine: true, + Hidden: true, + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + manPage, err := mcobra.NewManPage(1, cmd.Root()) + if err != nil { + return err + } + + _, err = fmt.Fprint(os.Stdout, manPage.Build(roff.NewDocument())) + return err + }, + }) + if err := rootCmd.Execute(); err != nil { if !errors.Is(err, errParsing) { log.Err(err).Msg("terminated with errors") diff --git a/go.mod b/go.mod index 1cdeaf2165..3f6ad27b93 100644 --- a/go.mod +++ b/go.mod @@ -56,6 +56,8 @@ require ( github.com/magefile/mage v1.15.0 github.com/mattn/go-isatty v0.0.20 github.com/mostynb/go-grpc-compression v1.2.2 + github.com/muesli/mango-cobra v1.2.0 + github.com/muesli/roff v0.1.0 github.com/ngrok/sqlmw v0.0.0-20220520173518-97c9c04efc79 github.com/ory/dockertest/v3 v3.10.0 github.com/outcaste-io/ristretto v0.2.3 @@ -273,6 +275,8 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/moricho/tparallel v0.3.1 // indirect + github.com/muesli/mango v0.1.0 // indirect + github.com/muesli/mango-pflag v0.1.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nakabonne/nestif v0.3.1 // indirect github.com/nishanths/exhaustive v0.12.0 // indirect diff --git a/go.sum b/go.sum index 4cc66511a0..078b06f0b4 100644 --- a/go.sum +++ b/go.sum @@ -652,6 +652,14 @@ github.com/moricho/tparallel v0.3.1 h1:fQKD4U1wRMAYNngDonW5XupoB/ZGJHdpzrWqgyg9k github.com/moricho/tparallel v0.3.1/go.mod h1:leENX2cUv7Sv2qDgdi0D0fCftN8fRC67Bcn8pqzeYNI= github.com/mostynb/go-grpc-compression v1.2.2 h1:XaDbnRvt2+1vgr0b/l0qh4mJAfIxE0bKXtz2Znl3GGI= github.com/mostynb/go-grpc-compression v1.2.2/go.mod h1:GOCr2KBxXcblCuczg3YdLQlcin1/NfyDA348ckuCH6w= +github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI= +github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4= +github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg= +github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA= +github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg= +github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0= +github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= +github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=