mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-19 02:02:55 +02:00
generate man page (#811)
[CLI.md](src/branch/main/docs/CLI.md) already gets generated using `urfave/cli-docs`. `cli-docs` can also generate man pages. This change extends the doc generator to also generate a man page for `tea`. * Add a subcommand to the doc generator to print the generated man page to stdout Closes #777. Co-authored-by: Valentin Brandl <mail@vbrandl.net> Reviewed-on: https://gitea.com/gitea/tea/pulls/811 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: TheFox0x7 <thefox0x7@noreply.gitea.com> Co-authored-by: Valentin Brandl <vbrandl@noreply.gitea.com> Co-committed-by: Valentin Brandl <vbrandl@noreply.gitea.com>
This commit is contained in:

committed by
Lunny Xiao

parent
cc20b52ab3
commit
4f513ca3e3
39
docs/docs.go
39
docs/docs.go
@ -6,9 +6,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"code.gitea.io/tea/cmd"
|
||||
docs "github.com/urfave/cli-docs/v3"
|
||||
@ -21,40 +19,9 @@ func main() {
|
||||
Name: "docs",
|
||||
Hidden: true,
|
||||
Description: "Generate CLI docs",
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
|
||||
md, err := docs.ToMarkdown(cmd.App())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outPath := c.String("out")
|
||||
if outPath == "" {
|
||||
fmt.Print(md)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(outPath), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fi, err := os.Create(outPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fi.Close()
|
||||
if _, err := fi.WriteString(md); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "out",
|
||||
Usage: "Path to output docs to, otherwise prints to stdout",
|
||||
Aliases: []string{"o"},
|
||||
},
|
||||
Flags: cmd.DocRenderFlags,
|
||||
Action: func(ctx context.Context, params *cli.Command) error {
|
||||
return cmd.RenderDocs(params, cmd.App(), docs.ToMarkdown)
|
||||
},
|
||||
}
|
||||
cli.Run(context.Background(), os.Args)
|
||||
|
Reference in New Issue
Block a user