github.com/fenixara/go@v0.0.0-20170127160404-96ea0918e670/src/cmd/go/help.go (about)

     1  // Copyright 2011 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  package main
     6  
     7  var helpC = &Command{
     8  	UsageLine: "c",
     9  	Short:     "calling between Go and C",
    10  	Long: `
    11  There are two different ways to call between Go and C/C++ code.
    12  
    13  The first is the cgo tool, which is part of the Go distribution.  For
    14  information on how to use it see the cgo documentation (go doc cmd/cgo).
    15  
    16  The second is the SWIG program, which is a general tool for
    17  interfacing between languages.  For information on SWIG see
    18  http://swig.org/.  When running go build, any file with a .swig
    19  extension will be passed to SWIG.  Any file with a .swigcxx extension
    20  will be passed to SWIG with the -c++ option.
    21  
    22  When either cgo or SWIG is used, go build will pass any .c, .m, .s,
    23  or .S files to the C compiler, and any .cc, .cpp, .cxx files to the C++
    24  compiler.  The CC or CXX environment variables may be set to determine
    25  the C or C++ compiler, respectively, to use.
    26  	`,
    27  }
    28  
    29  var helpPackages = &Command{
    30  	UsageLine: "packages",
    31  	Short:     "description of package lists",
    32  	Long: `
    33  Many commands apply to a set of packages:
    34  
    35  	go action [packages]
    36  
    37  Usually, [packages] is a list of import paths.
    38  
    39  An import path that is a rooted path or that begins with
    40  a . or .. element is interpreted as a file system path and
    41  denotes the package in that directory.
    42  
    43  Otherwise, the import path P denotes the package found in
    44  the directory DIR/src/P for some DIR listed in the GOPATH
    45  environment variable (For more details see: 'go help gopath').
    46  
    47  If no import paths are given, the action applies to the
    48  package in the current directory.
    49  
    50  There are four reserved names for paths that should not be used
    51  for packages to be built with the go tool:
    52  
    53  - "main" denotes the top-level package in a stand-alone executable.
    54  
    55  - "all" expands to all package directories found in all the GOPATH
    56  trees. For example, 'go list all' lists all the packages on the local
    57  system.
    58  
    59  - "std" is like all but expands to just the packages in the standard
    60  Go library.
    61  
    62  - "cmd" expands to the Go repository's commands and their
    63  internal libraries.
    64  
    65  Import paths beginning with "cmd/" only match source code in
    66  the Go repository.
    67  
    68  An import path is a pattern if it includes one or more "..." wildcards,
    69  each of which can match any string, including the empty string and
    70  strings containing slashes.  Such a pattern expands to all package
    71  directories found in the GOPATH trees with names matching the
    72  patterns.  As a special case, x/... matches x as well as x's subdirectories.
    73  For example, net/... expands to net and packages in its subdirectories.
    74  
    75  An import path can also name a package to be downloaded from
    76  a remote repository.  Run 'go help importpath' for details.
    77  
    78  Every package in a program must have a unique import path.
    79  By convention, this is arranged by starting each path with a
    80  unique prefix that belongs to you.  For example, paths used
    81  internally at Google all begin with 'google', and paths
    82  denoting remote repositories begin with the path to the code,
    83  such as 'github.com/user/repo'.
    84  
    85  Packages in a program need not have unique package names,
    86  but there are two reserved package names with special meaning.
    87  The name main indicates a command, not a library.
    88  Commands are built into binaries and cannot be imported.
    89  The name documentation indicates documentation for
    90  a non-Go program in the directory. Files in package documentation
    91  are ignored by the go command.
    92  
    93  As a special case, if the package list is a list of .go files from a
    94  single directory, the command is applied to a single synthesized
    95  package made up of exactly those files, ignoring any build constraints
    96  in those files and ignoring any other files in the directory.
    97  
    98  Directory and file names that begin with "." or "_" are ignored
    99  by the go tool, as are directories named "testdata".
   100  	`,
   101  }
   102  
   103  var helpImportPath = &Command{
   104  	UsageLine: "importpath",
   105  	Short:     "import path syntax",
   106  	Long: `
   107  
   108  An import path (see 'go help packages') denotes a package stored in the local
   109  file system.  In general, an import path denotes either a standard package (such
   110  as "unicode/utf8") or a package found in one of the work spaces (For more
   111  details see: 'go help gopath').
   112  
   113  Relative import paths
   114  
   115  An import path beginning with ./ or ../ is called a relative path.
   116  The toolchain supports relative import paths as a shortcut in two ways.
   117  
   118  First, a relative path can be used as a shorthand on the command line.
   119  If you are working in the directory containing the code imported as
   120  "unicode" and want to run the tests for "unicode/utf8", you can type
   121  "go test ./utf8" instead of needing to specify the full path.
   122  Similarly, in the reverse situation, "go test .." will test "unicode" from
   123  the "unicode/utf8" directory. Relative patterns are also allowed, like
   124  "go test ./..." to test all subdirectories. See 'go help packages' for details
   125  on the pattern syntax.
   126  
   127  Second, if you are compiling a Go program not in a work space,
   128  you can use a relative path in an import statement in that program
   129  to refer to nearby code also not in a work space.
   130  This makes it easy to experiment with small multipackage programs
   131  outside of the usual work spaces, but such programs cannot be
   132  installed with "go install" (there is no work space in which to install them),
   133  so they are rebuilt from scratch each time they are built.
   134  To avoid ambiguity, Go programs cannot use relative import paths
   135  within a work space.
   136  
   137  Remote import paths
   138  
   139  Certain import paths also
   140  describe how to obtain the source code for the package using
   141  a revision control system.
   142  
   143  A few common code hosting sites have special syntax:
   144  
   145  	Bitbucket (Git, Mercurial)
   146  
   147  		import "bitbucket.org/user/project"
   148  		import "bitbucket.org/user/project/sub/directory"
   149  
   150  	GitHub (Git)
   151  
   152  		import "github.com/user/project"
   153  		import "github.com/user/project/sub/directory"
   154  
   155  	Launchpad (Bazaar)
   156  
   157  		import "launchpad.net/project"
   158  		import "launchpad.net/project/series"
   159  		import "launchpad.net/project/series/sub/directory"
   160  
   161  		import "launchpad.net/~user/project/branch"
   162  		import "launchpad.net/~user/project/branch/sub/directory"
   163  
   164  	IBM DevOps Services (Git)
   165  
   166  		import "hub.jazz.net/git/user/project"
   167  		import "hub.jazz.net/git/user/project/sub/directory"
   168  
   169  For code hosted on other servers, import paths may either be qualified
   170  with the version control type, or the go tool can dynamically fetch
   171  the import path over https/http and discover where the code resides
   172  from a <meta> tag in the HTML.
   173  
   174  To declare the code location, an import path of the form
   175  
   176  	repository.vcs/path
   177  
   178  specifies the given repository, with or without the .vcs suffix,
   179  using the named version control system, and then the path inside
   180  that repository.  The supported version control systems are:
   181  
   182  	Bazaar      .bzr
   183  	Git         .git
   184  	Mercurial   .hg
   185  	Subversion  .svn
   186  
   187  For example,
   188  
   189  	import "example.org/user/foo.hg"
   190  
   191  denotes the root directory of the Mercurial repository at
   192  example.org/user/foo or foo.hg, and
   193  
   194  	import "example.org/repo.git/foo/bar"
   195  
   196  denotes the foo/bar directory of the Git repository at
   197  example.org/repo or repo.git.
   198  
   199  When a version control system supports multiple protocols,
   200  each is tried in turn when downloading.  For example, a Git
   201  download tries https://, then git+ssh://.
   202  
   203  By default, downloads are restricted to known secure protocols
   204  (e.g. https, ssh). To override this setting for Git downloads, the
   205  GIT_ALLOW_PROTOCOL environment variable can be set (For more details see:
   206  'go help environment').
   207  
   208  If the import path is not a known code hosting site and also lacks a
   209  version control qualifier, the go tool attempts to fetch the import
   210  over https/http and looks for a <meta> tag in the document's HTML
   211  <head>.
   212  
   213  The meta tag has the form:
   214  
   215  	<meta name="go-import" content="import-prefix vcs repo-root">
   216  
   217  The import-prefix is the import path corresponding to the repository
   218  root. It must be a prefix or an exact match of the package being
   219  fetched with "go get". If it's not an exact match, another http
   220  request is made at the prefix to verify the <meta> tags match.
   221  
   222  The meta tag should appear as early in the file as possible.
   223  In particular, it should appear before any raw JavaScript or CSS,
   224  to avoid confusing the go command's restricted parser.
   225  
   226  The vcs is one of "git", "hg", "svn", etc,
   227  
   228  The repo-root is the root of the version control system
   229  containing a scheme and not containing a .vcs qualifier.
   230  
   231  For example,
   232  
   233  	import "example.org/pkg/foo"
   234  
   235  will result in the following requests:
   236  
   237  	https://example.org/pkg/foo?go-get=1 (preferred)
   238  	http://example.org/pkg/foo?go-get=1  (fallback, only with -insecure)
   239  
   240  If that page contains the meta tag
   241  
   242  	<meta name="go-import" content="example.org git https://code.org/r/p/exproj">
   243  
   244  the go tool will verify that https://example.org/?go-get=1 contains the
   245  same meta tag and then git clone https://code.org/r/p/exproj into
   246  GOPATH/src/example.org.
   247  
   248  New downloaded packages are written to the first directory listed in the GOPATH
   249  environment variable (For more details see: 'go help gopath').
   250  
   251  The go command attempts to download the version of the
   252  package appropriate for the Go release being used.
   253  Run 'go help get' for more.
   254  
   255  Import path checking
   256  
   257  When the custom import path feature described above redirects to a
   258  known code hosting site, each of the resulting packages has two possible
   259  import paths, using the custom domain or the known hosting site.
   260  
   261  A package statement is said to have an "import comment" if it is immediately
   262  followed (before the next newline) by a comment of one of these two forms:
   263  
   264  	package math // import "path"
   265  	package math /* import "path" */
   266  
   267  The go command will refuse to install a package with an import comment
   268  unless it is being referred to by that import path. In this way, import comments
   269  let package authors make sure the custom import path is used and not a
   270  direct path to the underlying code hosting site.
   271  
   272  Import path checking is disabled for code found within vendor trees.
   273  This makes it possible to copy code into alternate locations in vendor trees
   274  without needing to update import comments.
   275  
   276  See https://golang.org/s/go14customimport for details.
   277  	`,
   278  }
   279  
   280  var helpGopath = &Command{
   281  	UsageLine: "gopath",
   282  	Short:     "GOPATH environment variable",
   283  	Long: `
   284  The Go path is used to resolve import statements.
   285  It is implemented by and documented in the go/build package.
   286  
   287  The GOPATH environment variable lists places to look for Go code.
   288  On Unix, the value is a colon-separated string.
   289  On Windows, the value is a semicolon-separated string.
   290  On Plan 9, the value is a list.
   291  
   292  If the environment variable is unset, GOPATH defaults
   293  to a subdirectory named "go" in the user's home directory
   294  ($HOME/go on Unix, %USERPROFILE%\go on Windows),
   295  unless that directory holds a Go distribution.
   296  Run "go env GOPATH" to see the current GOPATH.
   297  
   298  See https://golang.org/wiki/SettingGOPATH to set a custom GOPATH.
   299  
   300  Each directory listed in GOPATH must have a prescribed structure:
   301  
   302  The src directory holds source code.  The path below src
   303  determines the import path or executable name.
   304  
   305  The pkg directory holds installed package objects.
   306  As in the Go tree, each target operating system and
   307  architecture pair has its own subdirectory of pkg
   308  (pkg/GOOS_GOARCH).
   309  
   310  If DIR is a directory listed in the GOPATH, a package with
   311  source in DIR/src/foo/bar can be imported as "foo/bar" and
   312  has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a".
   313  
   314  The bin directory holds compiled commands.
   315  Each command is named for its source directory, but only
   316  the final element, not the entire path.  That is, the
   317  command with source in DIR/src/foo/quux is installed into
   318  DIR/bin/quux, not DIR/bin/foo/quux.  The "foo/" prefix is stripped
   319  so that you can add DIR/bin to your PATH to get at the
   320  installed commands.  If the GOBIN environment variable is
   321  set, commands are installed to the directory it names instead
   322  of DIR/bin. GOBIN must be an absolute path.
   323  
   324  Here's an example directory layout:
   325  
   326      GOPATH=/home/user/go
   327  
   328      /home/user/go/
   329          src/
   330              foo/
   331                  bar/               (go code in package bar)
   332                      x.go
   333                  quux/              (go code in package main)
   334                      y.go
   335          bin/
   336              quux                   (installed command)
   337          pkg/
   338              linux_amd64/
   339                  foo/
   340                      bar.a          (installed package object)
   341  
   342  Go searches each directory listed in GOPATH to find source code,
   343  but new packages are always downloaded into the first directory
   344  in the list.
   345  
   346  See https://golang.org/doc/code.html for an example.
   347  
   348  Internal Directories
   349  
   350  Code in or below a directory named "internal" is importable only
   351  by code in the directory tree rooted at the parent of "internal".
   352  Here's an extended version of the directory layout above:
   353  
   354      /home/user/go/
   355          src/
   356              crash/
   357                  bang/              (go code in package bang)
   358                      b.go
   359              foo/                   (go code in package foo)
   360                  f.go
   361                  bar/               (go code in package bar)
   362                      x.go
   363                  internal/
   364                      baz/           (go code in package baz)
   365                          z.go
   366                  quux/              (go code in package main)
   367                      y.go
   368  
   369  
   370  The code in z.go is imported as "foo/internal/baz", but that
   371  import statement can only appear in source files in the subtree
   372  rooted at foo. The source files foo/f.go, foo/bar/x.go, and
   373  foo/quux/y.go can all import "foo/internal/baz", but the source file
   374  crash/bang/b.go cannot.
   375  
   376  See https://golang.org/s/go14internal for details.
   377  
   378  Vendor Directories
   379  
   380  Go 1.6 includes support for using local copies of external dependencies
   381  to satisfy imports of those dependencies, often referred to as vendoring.
   382  
   383  Code below a directory named "vendor" is importable only
   384  by code in the directory tree rooted at the parent of "vendor",
   385  and only using an import path that omits the prefix up to and
   386  including the vendor element.
   387  
   388  Here's the example from the previous section,
   389  but with the "internal" directory renamed to "vendor"
   390  and a new foo/vendor/crash/bang directory added:
   391  
   392      /home/user/go/
   393          src/
   394              crash/
   395                  bang/              (go code in package bang)
   396                      b.go
   397              foo/                   (go code in package foo)
   398                  f.go
   399                  bar/               (go code in package bar)
   400                      x.go
   401                  vendor/
   402                      crash/
   403                          bang/      (go code in package bang)
   404                              b.go
   405                      baz/           (go code in package baz)
   406                          z.go
   407                  quux/              (go code in package main)
   408                      y.go
   409  
   410  The same visibility rules apply as for internal, but the code
   411  in z.go is imported as "baz", not as "foo/vendor/baz".
   412  
   413  Code in vendor directories deeper in the source tree shadows
   414  code in higher directories. Within the subtree rooted at foo, an import
   415  of "crash/bang" resolves to "foo/vendor/crash/bang", not the
   416  top-level "crash/bang".
   417  
   418  Code in vendor directories is not subject to import path
   419  checking (see 'go help importpath').
   420  
   421  When 'go get' checks out or updates a git repository, it now also
   422  updates submodules.
   423  
   424  Vendor directories do not affect the placement of new repositories
   425  being checked out for the first time by 'go get': those are always
   426  placed in the main GOPATH, never in a vendor subtree.
   427  
   428  See https://golang.org/s/go15vendor for details.
   429  	`,
   430  }
   431  
   432  var helpEnvironment = &Command{
   433  	UsageLine: "environment",
   434  	Short:     "environment variables",
   435  	Long: `
   436  
   437  The go command, and the tools it invokes, examine a few different
   438  environment variables. For many of these, you can see the default
   439  value of on your system by running 'go env NAME', where NAME is the
   440  name of the variable.
   441  
   442  General-purpose environment variables:
   443  
   444  	GCCGO
   445  		The gccgo command to run for 'go build -compiler=gccgo'.
   446  	GOARCH
   447  		The architecture, or processor, for which to compile code.
   448  		Examples are amd64, 386, arm, ppc64.
   449  	GOBIN
   450  		The directory where 'go install' will install a command.
   451  	GOOS
   452  		The operating system for which to compile code.
   453  		Examples are linux, darwin, windows, netbsd.
   454  	GOPATH
   455  		For more details see: 'go help gopath'.
   456  	GORACE
   457  		Options for the race detector.
   458  		See https://golang.org/doc/articles/race_detector.html.
   459  	GOROOT
   460  		The root of the go tree.
   461  
   462  Environment variables for use with cgo:
   463  
   464  	CC
   465  		The command to use to compile C code.
   466  	CGO_ENABLED
   467  		Whether the cgo command is supported.  Either 0 or 1.
   468  	CGO_CFLAGS
   469  		Flags that cgo will pass to the compiler when compiling
   470  		C code.
   471  	CGO_CPPFLAGS
   472  		Flags that cgo will pass to the compiler when compiling
   473  		C or C++ code.
   474  	CGO_CXXFLAGS
   475  		Flags that cgo will pass to the compiler when compiling
   476  		C++ code.
   477  	CGO_FFLAGS
   478  		Flags that cgo will pass to the compiler when compiling
   479  		Fortran code.
   480  	CGO_LDFLAGS
   481  		Flags that cgo will pass to the compiler when linking.
   482  	CXX
   483  		The command to use to compile C++ code.
   484  	PKG_CONFIG
   485  		Path to pkg-config tool.
   486  
   487  Architecture-specific environment variables:
   488  
   489  	GOARM
   490  		For GOARCH=arm, the ARM architecture for which to compile.
   491  		Valid values are 5, 6, 7.
   492  	GO386
   493  		For GOARCH=386, the floating point instruction set.
   494  		Valid values are 387, sse2.
   495  
   496  Special-purpose environment variables:
   497  
   498  	GOROOT_FINAL
   499  		The root of the installed Go tree, when it is
   500  		installed in a location other than where it is built.
   501  		File names in stack traces are rewritten from GOROOT to
   502  		GOROOT_FINAL.
   503  	GO_EXTLINK_ENABLED
   504  		Whether the linker should use external linking mode
   505  		when using -linkmode=auto with code that uses cgo.
   506  		Set to 0 to disable external linking mode, 1 to enable it.
   507  	GIT_ALLOW_PROTOCOL
   508  		Defined by Git. A colon-separated list of schemes that are allowed to be used
   509  		with git fetch/clone. If set, any scheme not explicitly mentioned will be
   510  		considered insecure by 'go get'.
   511  	`,
   512  }
   513  
   514  var helpFileType = &Command{
   515  	UsageLine: "filetype",
   516  	Short:     "file types",
   517  	Long: `
   518  The go command examines the contents of a restricted set of files
   519  in each directory. It identifies which files to examine based on
   520  the extension of the file name. These extensions are:
   521  
   522  	.go
   523  		Go source files.
   524  	.c, .h
   525  		C source files.
   526  		If the package uses cgo or SWIG, these will be compiled with the
   527  		OS-native compiler (typically gcc); otherwise they will
   528  		trigger an error.
   529  	.cc, .cpp, .cxx, .hh, .hpp, .hxx
   530  		C++ source files. Only useful with cgo or SWIG, and always
   531  		compiled with the OS-native compiler.
   532  	.m
   533  		Objective-C source files. Only useful with cgo, and always
   534  		compiled with the OS-native compiler.
   535  	.s, .S
   536  		Assembler source files.
   537  		If the package uses cgo or SWIG, these will be assembled with the
   538  		OS-native assembler (typically gcc (sic)); otherwise they
   539  		will be assembled with the Go assembler.
   540  	.swig, .swigcxx
   541  		SWIG definition files.
   542  	.syso
   543  		System object files.
   544  
   545  Files of each of these types except .syso may contain build
   546  constraints, but the go command stops scanning for build constraints
   547  at the first item in the file that is not a blank line or //-style
   548  line comment. See the go/build package documentation for
   549  more details.
   550  
   551  Non-test Go source files can also include a //go:binary-only-package
   552  comment, indicating that the package sources are included
   553  for documentation only and must not be used to build the
   554  package binary. This enables distribution of Go packages in
   555  their compiled form alone. See the go/build package documentation
   556  for more details.
   557  	`,
   558  }
   559  
   560  var helpBuildmode = &Command{
   561  	UsageLine: "buildmode",
   562  	Short:     "description of build modes",
   563  	Long: `
   564  The 'go build' and 'go install' commands take a -buildmode argument which
   565  indicates which kind of object file is to be built. Currently supported values
   566  are:
   567  
   568  	-buildmode=archive
   569  		Build the listed non-main packages into .a files. Packages named
   570  		main are ignored.
   571  
   572  	-buildmode=c-archive
   573  		Build the listed main package, plus all packages it imports,
   574  		into a C archive file. The only callable symbols will be those
   575  		functions exported using a cgo //export comment. Requires
   576  		exactly one main package to be listed.
   577  
   578  	-buildmode=c-shared
   579  		Build the listed main packages, plus all packages that they
   580  		import, into C shared libraries. The only callable symbols will
   581  		be those functions exported using a cgo //export comment.
   582  		Non-main packages are ignored.
   583  
   584  	-buildmode=default
   585  		Listed main packages are built into executables and listed
   586  		non-main packages are built into .a files (the default
   587  		behavior).
   588  
   589  	-buildmode=shared
   590  		Combine all the listed non-main packages into a single shared
   591  		library that will be used when building with the -linkshared
   592  		option. Packages named main are ignored.
   593  
   594  	-buildmode=exe
   595  		Build the listed main packages and everything they import into
   596  		executables. Packages not named main are ignored.
   597  
   598  	-buildmode=pie
   599  		Build the listed main packages and everything they import into
   600  		position independent executables (PIE). Packages not named
   601  		main are ignored.
   602  
   603  	-buildmode=plugin
   604  		Build the listed main packages, plus all packages that they
   605  		import, into a Go plugin. Packages not named main are ignored.
   606  `,
   607  }