This is a creation in Article, where the information may have evolved or changed.
Delve
Used cobra
to construct command tree
. Look first root command
, namely dlv
:
Func New () *cobra. command {...//Main DLV root command. Rootcommand = &cobra. command{use: "DLV", Short: "Delve are a debugger for the Go programming language.", Long:dlvcomma Ndlongdesc,} rootcommand.persistentflags (). Stringvarp (&ADDR, "Listen", "L", "localhost:0", "Debugging Server Listen address.") Rootcommand.persistentflags (). Boolvarp (&log, "Log", "" ", False," Enable Debugging Server Logging. ") Rootcommand.persistentflags (). Boolvarp (&headless, "Headless", "" "," false "," Run Debug server only, in Headless mode. ") Rootcommand.persistentflags (). Boolvarp (&acceptmulti, "accept-multiclient", "" "," false, "allows a headless server to accept multiple client connection S. Note the server API is not reentrant and clients'll has to coordinate ") rootcommand.persistentflags (). Intvar (&apiversion, "api-version", 1, "selects API version when headless") rootcommand.persistentflags (). Stringvar (&initfile, "Init", "", "Init file, executed by the terminal client.") Rootcommand.persistentflags (). Stringvar (&buildflags, "Build-flags", Buildflagsdefault, "build flags, to is passed to the compiler.") ......}
Because dlv command
there is no implementation run
function, running dlv
the command alone will only print cobra
the default output that helps generate:
# dlvDelve is a source level debugger for Go programs.......Usage: dlv [command]Available Commands: version Prints version. ......Flags: --accept-multiclient[=false]: Allows a headless server to accept multiple client connections. Note that the server API is not reentrant and clients will have to coordinate ......
In turn Long description
, Usage
and Available Commands
so on.
Again trace subcommand
, for example, see How to subcommand
add to the root command
inside:
......// 'trace' subcommand.traceCommand := &cobra.Command{ Use: "trace [package] regexp", Short: "Compile and begin tracing program.", Long: "Trace program execution. Will set a tracepoint on every function matching the provided regular expression and output information when tracepoint is hit.", Run: traceCmd,}traceCommand.Flags().IntVarP(&traceAttachPid, "pid", "p", 0, "Pid to attach to.")traceCommand.Flags().IntVarP(&traceStackDepth, "stack", "s", 0, "Show stack trace with given depth.")RootCommand.AddCommand(traceCommand)......
Cobra
Available in two types flags
:
A) Persistent Flags
: valid for both the current command and its sub-commands;
b) Local Flags
: Valid only for the current command.