CARGO-NEW(1)

πŸ“¦
version 1.99.1 Β· 6 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0

🌸 CARGO-NEW(1) β€” the manual page, but make it cute πŸ’…

okay bestie, welcome to cargo-new β€” the "omg new project era" command ✨ (yes the manual page is literally called CARGO-NEW(1), we love a title moment)


✨ NAME ✨

cargo-new β€” Create a new Cargo package πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

cargo new [options] path

πŸ’– DESCRIPTION πŸ’–

okay so. this command creates a brand new Cargo package in whatever directory you point it at. it's giving starter pack: you get a simple template with a Cargo.toml manifest, a sample source file, and a VCS ignore file. and if the directory isn't already chilling inside a VCS repository? it literally makes a new repository for you (see --vcs down below, iykyk). πŸ‘‘

also!! if you want a similar command that creates a new manifest in an existing directory, go look at cargo-init(1). sibling behavior fr fr 🫢


🌈 OPTIONS 🌈

πŸŽ€ New Options πŸŽ€

  • --bin β€” Create a package with a binary target (src/main.rs). This is the default behavior, so if you do nothing, this is what you get. main character energy by default ✨
  • --lib β€” Create a package with a library target (src/lib.rs). library girlies rise πŸ¦‹
  • --edition edition β€” Specify the Rust edition to use. Default is 2024. Possible values: 2015, 2018, 2021, 2024. pick your era, bestie πŸ’…
  • --name name β€” Set the package name. Defaults to the directory name. so if you don't name it, it just steals the folder's name, iconic tbh πŸ™ˆ
  • --vcs vcs β€” Initialize a new VCS repository for the given version control system (git, hg, pijul, or fossil) or do not initialize any version control at all (none). If not specified, defaults to git or the configuration value cargo-new.vcs, or none if already inside a VCS repository. no cap, it checks where you already are πŸ‘€
  • --registry registry β€” This sets the publish field in Cargo.toml to the given registry name which will restrict publishing only to that registry.

Registry names are defined in Cargo config files https://doc.rust-lang.org/cargo/reference/config.html. If not specified, the default registry defined by the registry.default config key is used. If the default registry is not set and --registry is not used, the publish field will not be set which means that publishing will not be restricted. so it's a whole "who am I allowed to publish to" situation ⭐

πŸ’… Display Options πŸ’…

  • -v, --verbose β€” Use verbose output. May be specified twice for "very verbose" output which includes extra output such as dependency warnings and build script output. May also be specified with the term.verbose config value https://doc.rust-lang.org/cargo/reference/config.html. double it for the extra tea πŸ“
  • -q, --quiet β€” Do not print cargo log messages. May also be specified with the term.quiet config value https://doc.rust-lang.org/cargo/reference/config.html. shhh era 🀫
  • --color when β€” Control when colored output is used. Valid values:
    • auto (default): Automatically detect if color support is available on the terminal.
    • always: Always display colors.
    • never: Never display colors.

May also be specified with the term.color config value https://doc.rust-lang.org/cargo/reference/config.html. we love a colorful terminal πŸ’–

πŸ‘‘ Common Options πŸ‘‘

  • +toolchain β€” If Cargo has been installed with rustup, and the first argument to cargo begins with +, it will be interpreted as a rustup toolchain name (such as +stable or +nightly). See the rustup documentation https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work. yes you can just be like "+nightly" and it obeys 🧚
  • --config KEY=VALUE or PATH β€” Overrides a Cargo configuration value. The argument should be in TOML syntax of KEY=VALUE, or provided as a path to an extra configuration file. This flag may be specified multiple times. See the command-line overrides section https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information. stack it as many times as you want, obsessed πŸ’œ
  • -C PATH β€” Changes the current working directory before executing any specified operations. This affects things like where cargo looks by default for the project manifest (Cargo.toml), as well as the directories searched for discovering .cargo/config.toml, for example. This option must appear before the command name, for example cargo -C path/to/my-project build.
⚠️ heads up bestie: this option is only available on the nightly channel https://doc.rust-lang.org/book/appendix-07-nightly-rust.html and requires the -Z unstable-options flag to enable (see #10098 https://github.com/rust-lang/cargo/issues/10098). so like… not for everyone yet 😭
  • -h, --help β€” Prints help information. the classic 🫢
  • -Z flag β€” Unstable (nightly-only) flags to Cargo. Run cargo -Z help for details. chaotic experimental mode, enter at your own risk πŸ’€

🌸 ENVIRONMENT 🌸

See the reference https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. it's all in there, go peek πŸŽ€


⭐ EXIT STATUS ⭐

  • 0: Cargo succeeded. slay πŸ’…
  • 101: Cargo failed to complete. not slay 😭

πŸ’œ EXAMPLES πŸ’œ

  1. Create a binary Cargo package in the given directory:
cargo new foo

πŸ¦‹ SEE ALSO πŸ¦‹

cargo(1), cargo-init(1)


and that's the whole page, bestie β€” every last flag accounted for, no gatekeeping 🌈✨

mwah πŸ’‹ this was CARGO-NEW(1) (yep, same name top and bottom, it's a whole bookend situation), brought to you from the General Commands Manual. go make something cute, fr fr πŸŽ€
πŸ“¦ where this page comes from