Delve Code Analysis Note (4)--Build command tree

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

DelveUsed 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)......

CobraAvailable 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.