github.com/go-asm/go@v1.21.1-0.20240213172139-40c5ead50c48/cmd/go/workcmd/vendor.go (about) 1 // Copyright 2022 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 6 7 import ( 8 "context" 9 10 "github.com/go-asm/go/cmd/go/base" 11 "github.com/go-asm/go/cmd/go/cfg" 12 "github.com/go-asm/go/cmd/go/modcmd" 13 "github.com/go-asm/go/cmd/go/modload" 14 ) 15 16 var cmdVendor = &base.Command{ 17 UsageLine: "go work vendor [-e] [-v] [-o outdir]", 18 Short: "make vendored copy of dependencies", 19 Long: ` 20 Vendor resets the workspace's vendor directory to include all packages 21 needed to build and test all the workspace's packages. 22 It does not include test code for vendored packages. 23 24 The -v flag causes vendor to print the names of vendored 25 modules and packages to standard error. 26 27 The -e flag causes vendor to attempt to proceed despite errors 28 encountered while loading packages. 29 30 The -o flag causes vendor to create the vendor directory at the given 31 path instead of "vendor". The go command can only use a vendor directory 32 named "vendor" within the module root directory, so this flag is 33 primarily useful for other tools.`, 34 35 Run: runVendor, 36 } 37 38 var vendorE bool // if true, report errors but proceed anyway 39 var vendorO string // if set, overrides the default output directory 40 41 func init() { 42 cmdVendor.Flag.BoolVar(&cfg.BuildV, "v", false, "") 43 cmdVendor.Flag.BoolVar(&vendorE, "e", false, "") 44 cmdVendor.Flag.StringVar(&vendorO, "o", "", "") 45 base.AddChdirFlag(&cmdVendor.Flag) 46 base.AddModCommonFlags(&cmdVendor.Flag) 47 } 48 49 func runVendor(ctx context.Context, cmd *base.Command, args []string) { 50 modload.InitWorkfile() 51 if modload.WorkFilePath() == "" { 52 base.Fatalf("go: no go.work file found\n\t(run 'go work init' first or specify path using GOWORK environment variable)") 53 } 54 55 modcmd.RunVendor(ctx, vendorE, vendorO, args) 56 }