Skip to content

Commit

Permalink
cmd: add man generation command
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Mar 1, 2024
1 parent 57206a1 commit d987ada
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/spicedb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -82,6 +85,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")
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,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
Expand Down Expand Up @@ -254,6 +256,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.11.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,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=
Expand Down

0 comments on commit d987ada

Please sign in to comment.