]> Cypherpunks repositories - gostls13.git/commit
cmd/go: split go mod into multiple subcommands
authorRuss Cox <rsc@golang.org>
Sun, 29 Jul 2018 00:25:06 +0000 (20:25 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 1 Aug 2018 00:35:17 +0000 (00:35 +0000)
commit6121987a10b2c54bc4c48473353205753d91f807
treefcbb2090efe8a86daea4408d875adfe60d112238
parent16962faf998a2f84793c5ca8481f6686ae9e3024
cmd/go: split go mod into multiple subcommands

The current "go mod" command does too many things.
The design is unclear.

It looks like "everything you might want to do with modules"
which causes people to think all module operations go through
"go mod", which is the opposite of the seamless integration we're
going for. In particular too many people think "go mod -require"
and "go get" are the same.

It does make sense to put the module-specific functionality
under "go mod", but not as flags. Instead, split "go mod" into
multiple subcommands:

go mod edit   # old go mod -require ...
go mod fix    # old go mod -fix
go mod graph  # old go mod -graph
go mod init   # old go mod -init
go mod tidy   # old go mod -sync
go mod vendor # old go mod -vendor
go mod verify # old go mod -verify

Splitting out the individual commands makes both the docs
and the implementations dramatically easier to read.
It simplifies the command lines
(go mod -init -module m is now 'go mod init m')
and allows command-specific flags.

We've avoided subcommands in the go command to date, and we
should continue to avoid adding them unless it really makes
the experience significantly better. In this case, it does.

Creating subcommands required some changes in the core
command-parsing and help logic to generalize from one
level to multiple levels.

As part of having "go mod init" be a separate command,
this CL changes the failure behavior during module initialization
to be delayed until modules are actually needed.
Initialization can still happen early, but the base.Fatalf
is delayed until something needs to use modules.
This fixes a bunch of commands like 'go env' that were
unhelpfully failing with GO111MODULE=on when not in a
module directory.

Fixes #26432.
Fixes #26581.
Fixes #26596.
Fixes #26639.

Change-Id: I868db0babe8c288e8af684b29d4a5ae4825d6407
Reviewed-on: https://go-review.googlesource.com/126655
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
52 files changed:
src/cmd/go/alldocs.go
src/cmd/go/internal/base/base.go
src/cmd/go/internal/bug/bug.go
src/cmd/go/internal/clean/clean.go
src/cmd/go/internal/doc/doc.go
src/cmd/go/internal/envcmd/env.go
src/cmd/go/internal/fix/fix.go
src/cmd/go/internal/fmtcmd/fmt.go
src/cmd/go/internal/generate/generate.go
src/cmd/go/internal/get/get.go
src/cmd/go/internal/help/help.go
src/cmd/go/internal/list/list.go
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/modcmd/edit.go [new file with mode: 0644]
src/cmd/go/internal/modcmd/fix.go [new file with mode: 0644]
src/cmd/go/internal/modcmd/graph.go [new file with mode: 0644]
src/cmd/go/internal/modcmd/init.go [new file with mode: 0644]
src/cmd/go/internal/modcmd/mod.go
src/cmd/go/internal/modcmd/tidy.go [new file with mode: 0644]
src/cmd/go/internal/modcmd/vendor.go
src/cmd/go/internal/modcmd/verify.go
src/cmd/go/internal/modget/get.go
src/cmd/go/internal/modload/help.go
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/run/run.go
src/cmd/go/internal/test/test.go
src/cmd/go/internal/tool/tool.go
src/cmd/go/internal/version/version.go
src/cmd/go/internal/vet/vet.go
src/cmd/go/internal/work/build.go
src/cmd/go/internal/work/init.go
src/cmd/go/main.go
src/cmd/go/testdata/mod/mod_tidy.txt [moved from src/cmd/go/testdata/mod/mod_sync.txt with 90% similarity]
src/cmd/go/testdata/script/help.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_edit.txt
src/cmd/go/testdata/script/mod_enabled.txt
src/cmd/go/testdata/script/mod_find.txt
src/cmd/go/testdata/script/mod_get_commit.txt
src/cmd/go/testdata/script/mod_get_indirect.txt
src/cmd/go/testdata/script/mod_getmode_vendor.txt
src/cmd/go/testdata/script/mod_go_version.txt
src/cmd/go/testdata/script/mod_graph.txt
src/cmd/go/testdata/script/mod_internal.txt
src/cmd/go/testdata/script/mod_nomod.txt [new file with mode: 0644]
src/cmd/go/testdata/script/mod_replace.txt
src/cmd/go/testdata/script/mod_tidy_quote.txt [moved from src/cmd/go/testdata/script/mod_sync_quote.txt with 62% similarity]
src/cmd/go/testdata/script/mod_tidy_sum.txt [moved from src/cmd/go/testdata/script/mod_sync_sum.txt with 87% similarity]
src/cmd/go/testdata/script/mod_vendor.txt
src/cmd/go/testdata/script/mod_vendor_nodeps.txt
src/cmd/go/testdata/script/mod_verify.txt
src/cmd/go/testdata/script/mod_version_nomod.txt [deleted file]