]> Cypherpunks repositories - gostls13.git/commitdiff
doc: fill in 'go mod init' section of module documentation
authorJay Conrod <jayconrod@google.com>
Fri, 10 Jan 2020 21:00:29 +0000 (16:00 -0500)
committerJay Conrod <jayconrod@google.com>
Fri, 7 Feb 2020 18:08:01 +0000 (18:08 +0000)
Updates #33637

Change-Id: I9c1345d0fa7a1b6c98c33b8b0837706e5261d5b4
Reviewed-on: https://go-review.googlesource.com/c/go/+/214381
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Tyler Bui-Palsulich <tbp@google.com>
doc/modules.md

index 222920891ef1606d794680c42c198c97984c1da3..ca795551868cd8e11dd6d34516848409b8b70b22 100644 (file)
@@ -802,6 +802,51 @@ to standard error.
 <a id="go-mod-init"></a>
 ### `go mod init`
 
+Usage:
+
+```
+go mod init [module-path]
+```
+
+Example:
+
+```
+go mod init
+go mod init example.com/m
+```
+
+The `go mod init` command initializes and writes a new `go.mod` file in the
+current directory, in effect creating a new module rooted at the current
+directory. The `go.mod` file must not already exist.
+
+`init` accepts one optional argument, the [module path](#glos-module-path) for
+the new module. See [Module paths](#module-path) for instructions on choosing
+a module path. If the module path argument is omitted, `init` will attempt
+to infer the module path using import comments in `.go` files, vendoring tool
+configuration files, and the current directory (if in `GOPATH`).
+
+If a configuration file for a vendoring tool is present, `init` will attempt to
+import module requirements from it. `init` supports the following configuration
+files.
+
+* `GLOCKFILE` (Glock)
+* `Godeps/Godeps.json` (Godeps)
+* `Gopkg.lock` (dep)
+* `dependencies.tsv` (godeps)
+* `glide.lock` (glide)
+* `vendor.conf` (trash)
+* `vendor.yml` (govend)
+* `vendor/manifest` (gvt)
+* `vendor/vendor.json` (govendor)
+
+Vendoring tool configuration files can't always be translated with perfect
+fidelity. For example, if multiple packages within the same repository are
+imported at different versions, and the repository only contains one module, the
+imported `go.mod` can only require the module at one version. You may wish to
+run [`go list -m all`](#go-list-m) to check all versions in the [build
+list](#glos-build-list), and [`go mod tidy`](#go-mod-tidy) to add missing
+requirements and to drop unused requirements.
+
 <a id="go-mod-tidy"></a>
 ### `go mod tidy`