mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-31 09:15:26 +01:00 
			
		
		
		
	migrate tea to urfave v3 (#760)
I tested this somewhat, but I haven't been using the cli before so I'm not sure if there are changes - there shouldn't be though. Reviewed-on: https://gitea.com/gitea/tea/pulls/760 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: TheFox0x7 <thefox0x7@gmail.com> Co-committed-by: TheFox0x7 <thefox0x7@gmail.com>
This commit is contained in:
		
							
								
								
									
										61
									
								
								docs/docs.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								docs/docs.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| // Copyright 2023 The Gitea Authors. All rights reserved. | ||||
| // SPDX-License-Identifier: MIT | ||||
|  | ||||
| //go:generates | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
|  | ||||
| 	"code.gitea.io/tea/cmd" | ||||
| 	docs "github.com/urfave/cli-docs/v3" | ||||
| 	"github.com/urfave/cli/v3" | ||||
| ) | ||||
|  | ||||
| // CmdDocs generates markdown for tea | ||||
| func main() { | ||||
| 	cli := &cli.Command{ | ||||
| 		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"}, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	cli.Run(context.Background(), os.Args) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 TheFox0x7
					TheFox0x7