github.com/neilgarb/delve@v1.9.2-nobreaks/pkg/terminal/docgen.go (about)

     1  package terminal
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"strings"
     7  )
     8  
     9  func replaceDocPath(s string) string {
    10  	const docpath = "$GOPATH/src/github.com/go-delve/delve/"
    11  
    12  	for {
    13  		start := strings.Index(s, docpath)
    14  		if start < 0 {
    15  			return s
    16  		}
    17  		var end int
    18  		for end = start + len(docpath); end < len(s); end++ {
    19  			if s[end] == ' ' {
    20  				break
    21  			}
    22  		}
    23  
    24  		text := s[start+len(docpath) : end]
    25  		s = s[:start] + fmt.Sprintf("[%s](//github.com/go-delve/delve/tree/master/%s)", text, text) + s[end:]
    26  	}
    27  }
    28  
    29  func (commands *Commands) WriteMarkdown(w io.Writer) {
    30  	fmt.Fprint(w, "# Configuration and Command History\n\n")
    31  	fmt.Fprint(w, "If `$XDG_CONFIG_HOME` is set, then configuration and command history files are located in `$XDG_CONFIG_HOME/dlv`. ")
    32  	fmt.Fprint(w, "Otherwise, they are located in `$HOME/.config/dlv` on Linux and `$HOME/.dlv` on other systems.\n\n")
    33  	fmt.Fprint(w, "The configuration file `config.yml` contains all the configurable options and their default values. ")
    34  	fmt.Fprint(w, "The command history is stored in `.dbg_history`.\n\n")
    35  
    36  	fmt.Fprint(w, "# Commands\n")
    37  
    38  	for _, cgd := range commandGroupDescriptions {
    39  		fmt.Fprintf(w, "\n## %s\n\n", cgd.description)
    40  
    41  		fmt.Fprint(w, "Command | Description\n")
    42  		fmt.Fprint(w, "--------|------------\n")
    43  		for _, cmd := range commands.cmds {
    44  			if cmd.group != cgd.group {
    45  				continue
    46  			}
    47  			h := cmd.helpMsg
    48  			if idx := strings.Index(h, "\n"); idx >= 0 {
    49  				h = h[:idx]
    50  			}
    51  			fmt.Fprintf(w, "[%s](#%s) | %s\n", cmd.aliases[0], cmd.aliases[0], h)
    52  		}
    53  		fmt.Fprint(w, "\n")
    54  
    55  	}
    56  
    57  	for _, cmd := range commands.cmds {
    58  		fmt.Fprintf(w, "## %s\n%s\n\n", cmd.aliases[0], replaceDocPath(cmd.helpMsg))
    59  		if len(cmd.aliases) > 1 {
    60  			fmt.Fprint(w, "Aliases:")
    61  			for _, alias := range cmd.aliases[1:] {
    62  				fmt.Fprintf(w, " %s", alias)
    63  			}
    64  			fmt.Fprint(w, "\n")
    65  		}
    66  		fmt.Fprint(w, "\n")
    67  	}
    68  }