Source file src/cmd/go/internal/workcmd/work.go

     1  // Copyright 2021 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 workcmd implements the “go work” command.
     6  package workcmd
     7  
     8  import (
     9  	"cmd/go/internal/base"
    10  )
    11  
    12  var CmdWork = &base.Command{
    13  	UsageLine: "go work",
    14  	Short:     "workspace maintenance",
    15  	Long: `Work provides access to operations on workspaces.
    16  
    17  Note that support for workspaces is built into many other commands, not
    18  just 'go work'.
    19  
    20  See 'go help modules' for information about Go's module system of which
    21  workspaces are a part.
    22  
    23  See https://go.dev/ref/mod#workspaces for an in-depth reference on
    24  workspaces.
    25  
    26  See https://go.dev/doc/tutorial/workspaces for an introductory
    27  tutorial on workspaces.
    28  
    29  A workspace is specified by a go.work file that specifies a set of
    30  module directories with the "use" directive. These modules are used as
    31  root modules by the go command for builds and related operations.  A
    32  workspace that does not specify modules to be used cannot be used to do
    33  builds from local modules.
    34  
    35  go.work files are line-oriented. Each line holds a single directive,
    36  made up of a keyword followed by arguments. For example:
    37  
    38  	go 1.18
    39  
    40  	use ../foo/bar
    41  	use ./baz
    42  
    43  	replace example.com/foo v1.2.3 => example.com/bar v1.4.5
    44  
    45  The leading keyword can be factored out of adjacent lines to create a block,
    46  like in Go imports.
    47  
    48  	use (
    49  	  ../foo/bar
    50  	  ./baz
    51  	)
    52  
    53  The use directive specifies a module to be included in the workspace's
    54  set of main modules. The argument to the use directive is the directory
    55  containing the module's go.mod file.
    56  
    57  The go directive specifies the version of Go the file was written at. It
    58  is possible there may be future changes in the semantics of workspaces
    59  that could be controlled by this version, but for now the version
    60  specified has no effect.
    61  
    62  The replace directive has the same syntax as the replace directive in a
    63  go.mod file and takes precedence over replaces in go.mod files.  It is
    64  primarily intended to override conflicting replaces in different workspace
    65  modules.
    66  
    67  To determine whether the go command is operating in workspace mode, use
    68  the "go env GOWORK" command. This will specify the workspace file being
    69  used.
    70  `,
    71  
    72  	Commands: []*base.Command{
    73  		cmdEdit,
    74  		cmdInit,
    75  		cmdSync,
    76  		cmdUse,
    77  		cmdVendor,
    78  	},
    79  }
    80  

View as plain text