Alternate init modes #186
Description
To accommodate the variety of ways people currently manage their Go code and make the transition to dep
as easy as possible, we want to give dep init
different operational modes. This is a meta-issue for discussing and tracking all these different modes we might implement.
Currently, dep init
works by:
- Analyzing the imports in your project
- Searching the GOPATH in which your project is located for these imports
- If not found, it adds the project to a list for gps to solve
- If found, it reads the vcs version from disk and uses that as the initial constraint in the manifest
- Step 4 is repeated transitively until we've run out of imports to visit
- If any imports weren't found on disk, we run a solve to pick versions for those,
populating the manifest with versions from the solution (only for missing direct deps, though); they are added to the lock, but omitted from the manifest.
This is a reasonable model for people who've been using GOPATH in the conventional/vanilla way: it's basically just pulling up information from what's on disk into your manifest, so that dep can then replicate everything under vendor
. However, this hardly the only way that may make sense for init to work.
Converting existing tools
First, there's converting over from an existing community tool. The basic approach here is to write a converter - something that reads the metadata files from the tool and translates them into the dep
equivalent.
There's a bunch of prior art to work from here, fortunately: glide does these sorts of conversions automatically. In the work I was doing to slot gps in as the engine for glide, I updated the converters for gb, godep, gom, and gpm to be gps-style. These write to glide's version of manifests and locks, but those are quite analogous to dep, and should be easy to adapt. There's also an open PR for converting from govendor, though that's to existing glide structs, not the gps-adapted versions of them. (No help for gvt or anything else, unfortunately)
Now, we might ultimately decide we want to keep these tool-specific converters external to dep - maybe in a fully separate converter tool, or just ask the maintainers to add such commands themselves. Either way, though, it doesn't hurt to write them here now.
Just the network, please
Another alternate mode might be to ignore all the existing local information - GOPATH, existing tools, everything - and just have the solver pick out the latest versions it can. This might be surprisingly worthwhile, especially for projects that may have been lagging behind.
Interactive selection
All of these preceding options are more or less separate modes (with "just the network" being a supplemental fallback that can automatically fill in holes left by any others). However, there's another orthogonal option that we may want: prompting the user to select the version they want. I'm imagining two, mutually exclusive options:
-prompt-missing
, where the tool prompts the user to pick a version available upstream only if the main mode provides no useful constraint-prompt-all
, where the user is prompted to choose from among the available upstream versions, and the version determined by the main inferencing mode (if any).