github.com/bgentry/go@v0.0.0-20150121062915-6cf5a733d54d/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 (godoc 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 (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 three 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  An import path is a pattern if it includes one or more "..." wildcards,
    63  each of which can match any string, including the empty string and
    64  strings containing slashes.  Such a pattern expands to all package
    65  directories found in the GOPATH trees with names matching the
    66  patterns.  As a special case, x/... matches x as well as x's subdirectories.
    67  For example, net/... expands to net and packages in its subdirectories.
    68  
    69  An import path can also name a package to be downloaded from
    70  a remote repository.  Run 'go help importpath' for details.
    71  
    72  Every package in a program must have a unique import path.
    73  By convention, this is arranged by starting each path with a
    74  unique prefix that belongs to you.  For example, paths used
    75  internally at Google all begin with 'google', and paths
    76  denoting remote repositories begin with the path to the code,
    77  such as 'code.google.com/p/project'.
    78  
    79  As a special case, if the package list is a list of .go files from a
    80  single directory, the command is applied to a single synthesized
    81  package made up of exactly those files, ignoring any build constraints
    82  in those files and ignoring any other files in the directory.
    83  
    84  Directory and file names that begin with "." or "_" are ignored
    85  by the go tool, as are directories named "testdata".
    86  	`,
    87  }
    88  
    89  var helpImportPath = &Command{
    90  	UsageLine: "importpath",
    91  	Short:     "import path syntax",
    92  	Long: `
    93  
    94  An import path (see 'go help packages') denotes a package
    95  stored in the local file system.  In general, an import path denotes
    96  either a standard package (such as "unicode/utf8") or a package
    97  found in one of the work spaces (see 'go help gopath').
    98  
    99  Relative import paths
   100  
   101  An import path beginning with ./ or ../ is called a relative path.
   102  The toolchain supports relative import paths as a shortcut in two ways.
   103  
   104  First, a relative path can be used as a shorthand on the command line.
   105  If you are working in the directory containing the code imported as
   106  "unicode" and want to run the tests for "unicode/utf8", you can type
   107  "go test ./utf8" instead of needing to specify the full path.
   108  Similarly, in the reverse situation, "go test .." will test "unicode" from
   109  the "unicode/utf8" directory. Relative patterns are also allowed, like
   110  "go test ./..." to test all subdirectories. See 'go help packages' for details
   111  on the pattern syntax.
   112  
   113  Second, if you are compiling a Go program not in a work space,
   114  you can use a relative path in an import statement in that program
   115  to refer to nearby code also not in a work space.
   116  This makes it easy to experiment with small multipackage programs
   117  outside of the usual work spaces, but such programs cannot be
   118  installed with "go install" (there is no work space in which to install them),
   119  so they are rebuilt from scratch each time they are built.
   120  To avoid ambiguity, Go programs cannot use relative import paths
   121  within a work space.
   122  
   123  Remote import paths
   124  
   125  Certain import paths also
   126  describe how to obtain the source code for the package using
   127  a revision control system.
   128  
   129  A few common code hosting sites have special syntax:
   130  
   131  	Bitbucket (Git, Mercurial)
   132  
   133  		import "bitbucket.org/user/project"
   134  		import "bitbucket.org/user/project/sub/directory"
   135  
   136  	GitHub (Git)
   137  
   138  		import "github.com/user/project"
   139  		import "github.com/user/project/sub/directory"
   140  
   141  	Google Code Project Hosting (Git, Mercurial, Subversion)
   142  
   143  		import "code.google.com/p/project"
   144  		import "code.google.com/p/project/sub/directory"
   145  
   146  		import "code.google.com/p/project.subrepository"
   147  		import "code.google.com/p/project.subrepository/sub/directory"
   148  
   149  	Launchpad (Bazaar)
   150  
   151  		import "launchpad.net/project"
   152  		import "launchpad.net/project/series"
   153  		import "launchpad.net/project/series/sub/directory"
   154  
   155  		import "launchpad.net/~user/project/branch"
   156  		import "launchpad.net/~user/project/branch/sub/directory"
   157  
   158  	IBM DevOps Services (Git)
   159  
   160  		import "hub.jazz.net/git/user/project"
   161  		import "hub.jazz.net/git/user/project/sub/directory"
   162  
   163  For code hosted on other servers, import paths may either be qualified
   164  with the version control type, or the go tool can dynamically fetch
   165  the import path over https/http and discover where the code resides
   166  from a <meta> tag in the HTML.
   167  
   168  To declare the code location, an import path of the form
   169  
   170  	repository.vcs/path
   171  
   172  specifies the given repository, with or without the .vcs suffix,
   173  using the named version control system, and then the path inside
   174  that repository.  The supported version control systems are:
   175  
   176  	Bazaar      .bzr
   177  	Git         .git
   178  	Mercurial   .hg
   179  	Subversion  .svn
   180  
   181  For example,
   182  
   183  	import "example.org/user/foo.hg"
   184  
   185  denotes the root directory of the Mercurial repository at
   186  example.org/user/foo or foo.hg, and
   187  
   188  	import "example.org/repo.git/foo/bar"
   189  
   190  denotes the foo/bar directory of the Git repository at
   191  example.org/repo or repo.git.
   192  
   193  When a version control system supports multiple protocols,
   194  each is tried in turn when downloading.  For example, a Git
   195  download tries git://, then https://, then http://.
   196  
   197  If the import path is not a known code hosting site and also lacks a
   198  version control qualifier, the go tool attempts to fetch the import
   199  over https/http and looks for a <meta> tag in the document's HTML
   200  <head>.
   201  
   202  The meta tag has the form:
   203  
   204  	<meta name="go-import" content="import-prefix vcs repo-root">
   205  
   206  The import-prefix is the import path corresponding to the repository
   207  root. It must be a prefix or an exact match of the package being
   208  fetched with "go get". If it's not an exact match, another http
   209  request is made at the prefix to verify the <meta> tags match.
   210  
   211  The vcs is one of "git", "hg", "svn", etc,
   212  
   213  The repo-root is the root of the version control system
   214  containing a scheme and not containing a .vcs qualifier.
   215  
   216  For example,
   217  
   218  	import "example.org/pkg/foo"
   219  
   220  will result in the following request(s):
   221  
   222  	https://example.org/pkg/foo?go-get=1 (preferred)
   223  	http://example.org/pkg/foo?go-get=1  (fallback)
   224  
   225  If that page contains the meta tag
   226  
   227  	<meta name="go-import" content="example.org git https://code.org/r/p/exproj">
   228  
   229  the go tool will verify that https://example.org/?go-get=1 contains the
   230  same meta tag and then git clone https://code.org/r/p/exproj into
   231  GOPATH/src/example.org.
   232  
   233  New downloaded packages are written to the first directory
   234  listed in the GOPATH environment variable (see 'go help gopath').
   235  
   236  The go command attempts to download the version of the
   237  package appropriate for the Go release being used.
   238  Run 'go help get' for more.
   239  
   240  Import path checking
   241  
   242  When the custom import path feature described above redirects to a
   243  known code hosting site, each of the resulting packages has two possible
   244  import paths, using the custom domain or the known hosting site.
   245  
   246  A package statement is said to have an "import comment" if it is immediately
   247  followed (before the next newline) by a comment of one of these two forms:
   248  
   249  	package math // import "path"
   250  	package math /* import "path" */
   251  
   252  The go command will refuse to install a package with an import comment
   253  unless it is being referred to by that import path. In this way, import comments
   254  let package authors make sure the custom import path is used and not a
   255  direct path to the underlying code hosting site.
   256  
   257  See https://golang.org/s/go14customimport for details.
   258  	`,
   259  }
   260  
   261  var helpGopath = &Command{
   262  	UsageLine: "gopath",
   263  	Short:     "GOPATH environment variable",
   264  	Long: `
   265  The Go path is used to resolve import statements.
   266  It is implemented by and documented in the go/build package.
   267  
   268  The GOPATH environment variable lists places to look for Go code.
   269  On Unix, the value is a colon-separated string.
   270  On Windows, the value is a semicolon-separated string.
   271  On Plan 9, the value is a list.
   272  
   273  GOPATH must be set to get, build and install packages outside the
   274  standard Go tree.
   275  
   276  Each directory listed in GOPATH must have a prescribed structure:
   277  
   278  The src/ directory holds source code.  The path below 'src'
   279  determines the import path or executable name.
   280  
   281  The pkg/ directory holds installed package objects.
   282  As in the Go tree, each target operating system and
   283  architecture pair has its own subdirectory of pkg
   284  (pkg/GOOS_GOARCH).
   285  
   286  If DIR is a directory listed in the GOPATH, a package with
   287  source in DIR/src/foo/bar can be imported as "foo/bar" and
   288  has its compiled form installed to "DIR/pkg/GOOS_GOARCH/foo/bar.a".
   289  
   290  The bin/ directory holds compiled commands.
   291  Each command is named for its source directory, but only
   292  the final element, not the entire path.  That is, the
   293  command with source in DIR/src/foo/quux is installed into
   294  DIR/bin/quux, not DIR/bin/foo/quux.  The foo/ is stripped
   295  so that you can add DIR/bin to your PATH to get at the
   296  installed commands.  If the GOBIN environment variable is
   297  set, commands are installed to the directory it names instead
   298  of DIR/bin.
   299  
   300  Here's an example directory layout:
   301  
   302      GOPATH=/home/user/gocode
   303  
   304      /home/user/gocode/
   305          src/
   306              foo/
   307                  bar/               (go code in package bar)
   308                      x.go
   309                  quux/              (go code in package main)
   310                      y.go
   311          bin/
   312              quux                   (installed command)
   313          pkg/
   314              linux_amd64/
   315                  foo/
   316                      bar.a          (installed package object)
   317  
   318  Go searches each directory listed in GOPATH to find source code,
   319  but new packages are always downloaded into the first directory
   320  in the list.
   321  	`,
   322  }
   323  
   324  var helpFileType = &Command{
   325  	UsageLine: "filetype",
   326  	Short:     "file types",
   327  	Long: `
   328  The go command examines the contents of a restricted set of files
   329  in each directory. It identifies which files to examine based on
   330  the extension of the file name. These extensions are:
   331  
   332  	.go
   333  		Go source files.
   334  	.c, .h
   335  		C source files.
   336  		If the package uses cgo, these will be compiled with the
   337  		OS-native compiler (typically gcc); otherwise they will be
   338  		compiled with the Go-specific support compiler,
   339  		5c, 6c, or 8c, etc. as appropriate.
   340  	.cc, .cpp, .cxx, .hh, .hpp, .hxx
   341  		C++ source files. Only useful with cgo or SWIG, and always
   342  		compiled with the OS-native compiler.
   343  	.m
   344  		Objective-C source files. Only useful with cgo, and always
   345  		compiled with the OS-native compiler.
   346  	.s, .S
   347  		Assembler source files.
   348  		If the package uses cgo, these will be assembled with the
   349  		OS-native assembler (typically gcc (sic)); otherwise they
   350  		will be assembled with the Go-specific support assembler,
   351  		5a, 6a, or 8a, etc., as appropriate.
   352  	.swig, .swigcxx
   353  		SWIG definition files.
   354  	.syso
   355  		System object files.
   356  
   357  Files of each of these types except .syso may contain build
   358  constraints, but the go command stops scanning for build constraints
   359  at the first item in the file that is not a blank line or //-style
   360  line comment.
   361  	`,
   362  }