mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-12 06:27:07 +08:00
docs: add external docs links support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:

committed by
Sebastiaan van Stijn

parent
363c0fdf4b
commit
4047bccf6c
@ -90,8 +90,18 @@ func genCmd(cmd *cobra.Command, dir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeLink(txt, link string) string {
|
||||
return "[" + txt + "](#" + link + ")"
|
||||
func makeLink(txt, link string, f *pflag.Flag, isAnchor bool) string {
|
||||
link = "#" + link
|
||||
annotations, ok := f.Annotations["docs.external.url"]
|
||||
if ok && len(annotations) > 0 {
|
||||
link = annotations[0]
|
||||
} else {
|
||||
if !isAnchor {
|
||||
return txt
|
||||
}
|
||||
}
|
||||
|
||||
return "[" + txt + "](" + link + ")"
|
||||
}
|
||||
|
||||
func cmdOutput(cmd *cobra.Command, old string) (string, error) {
|
||||
@ -140,9 +150,7 @@ func cmdOutput(cmd *cobra.Command, old string) (string, error) {
|
||||
fmt.Fprint(b, "| ")
|
||||
if f.Shorthand != "" {
|
||||
name := "`-" + f.Shorthand + "`"
|
||||
if isLink {
|
||||
name = makeLink(name, f.Name)
|
||||
}
|
||||
name = makeLink(name, f.Name, f, isLink)
|
||||
fmt.Fprintf(b, "%s, ", name)
|
||||
}
|
||||
name := "`--" + f.Name
|
||||
@ -150,9 +158,7 @@ func cmdOutput(cmd *cobra.Command, old string) (string, error) {
|
||||
name += " " + f.Value.Type()
|
||||
}
|
||||
name += "`"
|
||||
if isLink {
|
||||
name = makeLink(name, f.Name)
|
||||
}
|
||||
name = makeLink(name, f.Name, f, isLink)
|
||||
fmt.Fprintf(b, "%s | %s |\n", name, f.Usage)
|
||||
})
|
||||
fmt.Fprintln(b, "")
|
||||
|
Reference in New Issue
Block a user