// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// go work use

package workcmd

import (
	"context"
	"fmt"
	"io/fs"
	"os"
	"path/filepath"

	"cmd/go/internal/base"
	"cmd/go/internal/fsys"
	"cmd/go/internal/gover"
	"cmd/go/internal/modload"
	"cmd/go/internal/str"
	"cmd/go/internal/toolchain"

	"golang.org/x/mod/modfile"
)

var cmdUse = &base.Command{
	UsageLine: "go work use [-r] [moddirs]",
	Short:     "add modules to workspace file",
	Long: `Use provides a command-line interface for adding
directories, optionally recursively, to a go.work file.

A use directive will be added to the go.work file for each argument
directory listed on the command line go.work file, if it exists,
or removed from the go.work file if it does not exist.
Use fails if any remaining use directives refer to modules that
do not exist.

Use updates the go line in go.work to specify a version at least as
new as all the go lines in the used modules, both preexisting ones
and newly added ones. With no arguments, this update is the only
thing that go work use does.

The -r flag searches recursively for modules in the argument
directories, and the use command operates as if each of the directories
were specified as arguments. When -r is used, symlinks to directories
within the argument tree are ignored.

The go command matches use paths to module directories without resolving
symbolic links. A use directive that names a symlink to a directory is
not interchangeable with one that names the symlink's target.
