You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
6.0 KiB

  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. /*
  5. Godoc extracts and generates documentation for Go programs.
  6. It has two modes.
  7. Without the -http flag, it runs in command-line mode and prints plain text
  8. documentation to standard output and exits. If both a library package and
  9. a command with the same name exists, using the prefix cmd/ will force
  10. documentation on the command rather than the library package. If the -src
  11. flag is specified, godoc prints the exported interface of a package in Go
  12. source form, or the implementation of a specific exported language entity:
  13. godoc fmt # documentation for package fmt
  14. godoc fmt Printf # documentation for fmt.Printf
  15. godoc cmd/go # force documentation for the go command
  16. godoc -src fmt # fmt package interface in Go source form
  17. godoc -src fmt Printf # implementation of fmt.Printf
  18. In command-line mode, the -q flag enables search queries against a godoc running
  19. as a webserver. If no explicit server address is specified with the -server flag,
  20. godoc first tries localhost:6060 and then http://golang.org.
  21. godoc -q Reader
  22. godoc -q math.Sin
  23. godoc -server=:6060 -q sin
  24. With the -http flag, it runs as a web server and presents the documentation as a
  25. web page.
  26. godoc -http=:6060
  27. Usage:
  28. godoc [flag] package [name ...]
  29. The flags are:
  30. -v
  31. verbose mode
  32. -q
  33. arguments are considered search queries: a legal query is a
  34. single identifier (such as ToLower) or a qualified identifier
  35. (such as math.Sin)
  36. -src
  37. print (exported) source in command-line mode
  38. -tabwidth=4
  39. width of tabs in units of spaces
  40. -timestamps=true
  41. show timestamps with directory listings
  42. -index
  43. enable identifier and full text search index
  44. (no search box is shown if -index is not set)
  45. -index_files=""
  46. glob pattern specifying index files; if not empty,
  47. the index is read from these files in sorted order
  48. -index_throttle=0.75
  49. index throttle value; a value of 0 means no time is allocated
  50. to the indexer (the indexer will never finish), a value of 1.0
  51. means that index creation is running at full throttle (other
  52. goroutines may get no time while the index is built)
  53. -links=true:
  54. link identifiers to their declarations
  55. -write_index=false
  56. write index to a file; the file name must be specified with
  57. -index_files
  58. -maxresults=10000
  59. maximum number of full text search results shown
  60. (no full text index is built if maxresults <= 0)
  61. -notes="BUG"
  62. regular expression matching note markers to show
  63. (e.g., "BUG|TODO", ".*")
  64. -html
  65. print HTML in command-line mode
  66. -goroot=$GOROOT
  67. Go root directory
  68. -http=addr
  69. HTTP service address (e.g., '127.0.0.1:6060' or just ':6060')
  70. -server=addr
  71. webserver address for command line searches
  72. -analysis=type,pointer
  73. comma-separated list of analyses to perform
  74. "type": display identifier resolution, type info, method sets,
  75. 'implements', and static callees
  76. "pointer": display channel peers, callers and dynamic callees
  77. (significantly slower)
  78. See http://golang.org/lib/godoc/analysis/help.html for details.
  79. -templates=""
  80. directory containing alternate template files; if set,
  81. the directory may provide alternative template files
  82. for the files in $GOROOT/lib/godoc
  83. -url=path
  84. print to standard output the data that would be served by
  85. an HTTP request for path
  86. -zip=""
  87. zip file providing the file system to serve; disabled if empty
  88. By default, godoc looks at the packages it finds via $GOROOT and $GOPATH (if set).
  89. This behavior can be altered by providing an alternative $GOROOT with the -goroot
  90. flag.
  91. When godoc runs as a web server and -index is set, a search index is maintained.
  92. The index is created at startup.
  93. The index contains both identifier and full text search information (searchable
  94. via regular expressions). The maximum number of full text search results shown
  95. can be set with the -maxresults flag; if set to 0, no full text results are
  96. shown, and only an identifier index but no full text search index is created.
  97. By default, godoc uses the system's GOOS/GOARCH; in command-line mode you can
  98. set the GOOS/GOARCH environment variables to get output for the system specified.
  99. If -http was specified you can provide the URL parameters "GOOS" and "GOARCH"
  100. to set the output on the web page.
  101. The presentation mode of web pages served by godoc can be controlled with the
  102. "m" URL parameter; it accepts a comma-separated list of flag names as value:
  103. all show documentation for all declarations, not just the exported ones
  104. methods show all embedded methods, not just those of unexported anonymous fields
  105. src show the original source code rather then the extracted documentation
  106. text present the page in textual (command-line) form rather than HTML
  107. flat present flat (not indented) directory listings using full paths
  108. For instance, http://golang.org/pkg/math/big/?m=all,text shows the documentation
  109. for all (not just the exported) declarations of package big, in textual form (as
  110. it would appear when using godoc from the command line: "godoc -src math/big .*").
  111. By default, godoc serves files from the file system of the underlying OS.
  112. Instead, a .zip file may be provided via the -zip flag, which contains
  113. the file system to serve. The file paths stored in the .zip file must use
  114. slash ('/') as path separator; and they must be unrooted. $GOROOT (or -goroot)
  115. must be set to the .zip file directory path containing the Go root directory.
  116. For instance, for a .zip file created by the command:
  117. zip -r go.zip $HOME/go
  118. one may run godoc as follows:
  119. godoc -http=:6060 -zip=go.zip -goroot=$HOME/go
  120. Godoc documentation is converted to HTML or to text using the go/doc package;
  121. see http://golang.org/pkg/go/doc/#ToHTML for the exact rules.
  122. Godoc also shows example code that is runnable by the testing package;
  123. see http://golang.org/pkg/testing/#hdr-Examples for the conventions.
  124. See "Godoc: documenting Go code" for how to write good comments for godoc:
  125. http://golang.org/doc/articles/godoc_documenting_go_code.html
  126. */
  127. package main // import "golang.org/x/tools/cmd/godoc"