mirror of
https://github.com/go-delve/delve.git
synced 2025-10-27 03:56:24 +08:00
Documentation,cmd/dlv: clean up command line usage help (#3395)
Due to some very old mistakes too many of Delve's flags are declared as persistent on cobra's root command. For example the headless flag is a global flag but does not apply to connect, dap or trace; the backend flag does not apply to replay, core and dap; etc. Almost all global flags should have been declared as local flags on individual subcommands. Unfortunately we can not change this without breaking backwards compatibility, for example: dlv --headless debug would not parse if headless was a flag of debug instead of a global flag. Instead we alter usage function and the markdown generation script to strategically hide the flags that don't apply. Fixes #2361
This commit is contained in:
committed by
GitHub
parent
dc5d8de320
commit
caf6df0eb9
@ -10,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-delve/delve/cmd/dlv/cmds"
|
||||
"github.com/go-delve/delve/cmd/dlv/cmds/helphelpers"
|
||||
"github.com/spf13/cobra/doc"
|
||||
)
|
||||
|
||||
@ -21,12 +22,19 @@ func main() {
|
||||
usageDir = os.Args[1]
|
||||
}
|
||||
root := cmds.New(true)
|
||||
|
||||
cmdnames := []string{}
|
||||
for _, subcmd := range root.Commands() {
|
||||
cmdnames = append(cmdnames, subcmd.Name())
|
||||
}
|
||||
helphelpers.Prepare(root)
|
||||
doc.GenMarkdownTree(root, usageDir)
|
||||
root = nil
|
||||
// GenMarkdownTree ignores additional help topic commands, so we have to do this manually
|
||||
for _, cmd := range root.Commands() {
|
||||
if cmd.Run == nil {
|
||||
doc.GenMarkdownTree(cmd, usageDir)
|
||||
}
|
||||
for _, cmdname := range cmdnames {
|
||||
cmd, _, _ := cmds.New(true).Find([]string{cmdname})
|
||||
helphelpers.Prepare(cmd)
|
||||
doc.GenMarkdownTree(cmd, usageDir)
|
||||
}
|
||||
fh, err := os.OpenFile(filepath.Join(usageDir, "dlv.md"), os.O_APPEND|os.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user