File: docgen.go

package info (click to toggle)
delve 1.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,136 kB
  • sloc: ansic: 111,947; sh: 194; asm: 147; makefile: 43; python: 23
file content (89 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package terminal

import (
	"fmt"
	"io"
	"strings"
)

func replaceDocPath(s string) string {
	const docpath = "Documentation/"

	i0 := 0

	for {
		start := strings.Index(s[i0:], docpath)
		if start < 0 {
			return s
		}
		start += i0
		if start-1 >= 0 && s[start-1] != ' ' {
			i0 = start + len(docpath) + 1
			continue
		}
		var end int
		for end = start + len(docpath); end < len(s); end++ {
			if s[end] == ' ' {
				break
			}
		}
		// If we captured a trailing dot, backtrack.
		if s[end-1] == '.' {
			end--
		}

		text := s[start:end]
		s = s[:start] + fmt.Sprintf("[%s](//github.com/go-delve/delve/tree/master/%s)", text, text) + s[end:]
		i0 = end + 1
	}
}

func fixLessThan(s string) string {
	v := strings.Split(s, "\n")
	for i := range v {
		if len(v[i]) == 0 || v[i][0] != '\t' {
			v[i] = strings.ReplaceAll(v[i], "<", "&lt;")
		}
	}
	return strings.Join(v, "\n")
}

func (c *Commands) WriteMarkdown(w io.Writer) {
	fmt.Fprint(w, "# Configuration and Command History\n\n")
	fmt.Fprint(w, "If `$XDG_CONFIG_HOME` is set, then configuration and command history files are located in `$XDG_CONFIG_HOME/dlv`. ")
	fmt.Fprint(w, "Otherwise, they are located in `$HOME/.config/dlv` on Linux and `$HOME/.dlv` on other systems.\n\n")
	fmt.Fprint(w, "The configuration file `config.yml` contains all the configurable options and their default values. ")
	fmt.Fprint(w, "The command history is stored in `.dbg_history`.\n\n")

	fmt.Fprint(w, "# Commands\n")

	for _, cgd := range commandGroupDescriptions {
		fmt.Fprintf(w, "\n## %s\n\n", cgd.description)

		fmt.Fprint(w, "Command | Description\n")
		fmt.Fprint(w, "--------|------------\n")
		for _, cmd := range c.cmds {
			if cmd.group != cgd.group {
				continue
			}
			h := cmd.helpMsg
			if idx := strings.Index(h, "\n"); idx >= 0 {
				h = h[:idx]
			}
			fmt.Fprintf(w, "[%s](#%s) | %s\n", cmd.aliases[0], cmd.aliases[0], h)
		}
		fmt.Fprint(w, "\n")
	}

	for _, cmd := range c.cmds {
		fmt.Fprintf(w, "## %s\n%s\n\n", cmd.aliases[0], fixLessThan(replaceDocPath(cmd.helpMsg)))
		if len(cmd.aliases) > 1 {
			fmt.Fprint(w, "Aliases:")
			for _, alias := range cmd.aliases[1:] {
				fmt.Fprintf(w, " %s", alias)
			}
			fmt.Fprint(w, "\n")
		}
		fmt.Fprint(w, "\n")
	}
}