Description
openedon May 28, 2018
Cargo as well as cargo-edit have gone a long way since #4 was opened. It might now make sense to move (parts of) cargo-edit into cargo itself. Basically, we now have a format-preserving TOML library that -- at least for adding a dependency line -- work quite well (you can test this with cargo install cargo-edit --vers 0.3.0-beta.1 -f
).
Speaking with @matklad, I believe I now have a somewhat solid understanding of what needs to happen to add a new built-in cargo subcommand. One important realization was that cargo-install already contains some of the parts we need.
Here are some steps to get started:
- Create a
src/bin/cargo/commands/add.rs
(as duplicate ofinstall.rs
at first) - In
src/bin/cargo/commands/mod.rs
, addadd
tobuiltin
/builtin_exec
, and to the list ofmod
s - Create a
src/bin/cargo/ops/cargo_add.rs
(as duplicate ofcargo_install.rs
at first)
One thing we should aim for though, is to now just copy-paste the whole of cargo-edit but to re-use as much of cargo's infrastructure as possible. For example, we should try to use cargo's way of querying the registry as well as its CLI args handling and output formatting. We can, for example, also use args.workspace.current_manifest
to get the manifest and deal with workspace.