9

I have installed rust using curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh on Ubuntu.

But when I tried cargo generate --git https://github.com/CosmWasm/cw-template.git --name FOO I met the error like this error: no such subcommand: 'generate'

My cargo version is cargo 1.59.0 (49d8809dc 2022-02-10).

Why this happens?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Bikas Lin
  • 689
  • 5
  • 16

2 Answers2

13

You should install the cargo-generate with:

cargo install cargo-generate

Some cargo sub commands are built in, while others are installed separately. You can get the list of available sub commands with:

cargo --list
  • 2
    Note that the ‘others installed separately’ are also _unofficial._ A package’s name starting with `cargo-` doesn't mean anything about its authorship. – Kevin Reid Mar 17 '22 at 14:48
0

So turns out that even today cargo add <package> is not an official command. Its part of cargo edit. It is going to be added in the next Rust update supposedly. For now you have to edit the Cargo.toml file the old fashioned way.

Edit: to install and have the ability to use add subcommand now, run cargo install cargo-edit

gnu_byte
  • 41
  • 1
  • 5
  • Are you sure it's part of cargo-edit? The docs list only four other subcommands that are installed this way. Maybe cargo generate is a dependency? – Cornelius Roemer May 24 '22 at 07:19
  • After I installed cargo-edit, I was able to successfully use the `add` subcommand, yes. – gnu_byte May 25 '22 at 07:00