2017-03-19 22:45:54 +00:00
|
|
|
package terminal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func replaceDocPath(s string) string {
|
2019-04-15 14:43:01 +00:00
|
|
|
const docpath = "$GOPATH/src/github.com/go-delve/delve/"
|
2017-03-19 22:45:54 +00:00
|
|
|
|
|
|
|
for {
|
|
|
|
start := strings.Index(s, docpath)
|
|
|
|
if start < 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
var end int
|
|
|
|
for end = start + len(docpath); end < len(s); end++ {
|
|
|
|
if s[end] == ' ' {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
text := s[start+len(docpath) : end]
|
2019-04-15 14:43:01 +00:00
|
|
|
s = s[:start] + fmt.Sprintf("[%s](//github.com/go-delve/delve/tree/master/%s)", text, text) + s[end:]
|
2017-03-19 22:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (commands *Commands) WriteMarkdown(w io.Writer) {
|
2018-10-13 13:45:53 +00:00
|
|
|
fmt.Fprint(w, "# Commands\n\n")
|
2017-03-19 22:45:54 +00:00
|
|
|
|
2018-10-13 13:45:53 +00:00
|
|
|
fmt.Fprint(w, "Command | Description\n")
|
|
|
|
fmt.Fprint(w, "--------|------------\n")
|
2017-03-19 22:45:54 +00:00
|
|
|
for _, cmd := range commands.cmds {
|
|
|
|
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)
|
|
|
|
}
|
2018-10-13 13:45:53 +00:00
|
|
|
fmt.Fprint(w, "\n")
|
2017-03-19 22:45:54 +00:00
|
|
|
|
|
|
|
for _, cmd := range commands.cmds {
|
|
|
|
fmt.Fprintf(w, "## %s\n%s\n\n", cmd.aliases[0], replaceDocPath(cmd.helpMsg))
|
|
|
|
if len(cmd.aliases) > 1 {
|
2018-10-13 13:45:53 +00:00
|
|
|
fmt.Fprint(w, "Aliases:")
|
2017-03-19 22:45:54 +00:00
|
|
|
for _, alias := range cmd.aliases[1:] {
|
|
|
|
fmt.Fprintf(w, " %s", alias)
|
|
|
|
}
|
2018-10-13 13:45:53 +00:00
|
|
|
fmt.Fprint(w, "\n")
|
2017-03-19 22:45:54 +00:00
|
|
|
}
|
2018-10-13 13:45:53 +00:00
|
|
|
fmt.Fprint(w, "\n")
|
2017-03-19 22:45:54 +00:00
|
|
|
}
|
|
|
|
}
|