CARGO-INIT(1)

πŸ“¦ version 1.85.1, in ubuntu jammy, ubuntu noble, ubuntu questing

πŸ’– CARGO-INIT(1) πŸ’–

okay bestie, welcome to cargo-init β€” it's a manual page from the General Commands Manual, and it's here to teach you how to spin up a brand new Cargo package in a directory that already exists. no cap. let's get into it πŸ¦‹


✨ NAME ✨

cargo-init β€” create a new Cargo package in an existing directory 🌸


πŸŽ€ SYNOPSIS πŸŽ€

cargo init [options] [path]

🧚 DESCRIPTION 🧚

so basically, this command creates a new Cargo manifest in the current directory. it's giving main character energy ✨ and if you hand it a path as an argument, it'll go create the thing over in that directory instead. slay.

if there are typically-named Rust source files already chillin' in the directory, those get used. and if there aren't? no worries bestie, a sample src/main.rs file gets created β€” or src/lib.rs if you pass --lib. πŸ’…

and if the directory isn't already inside a VCS repository, then a whole new repository gets created (peep --vcs down below πŸ‘€).

also! go look at cargo-new(1) for a similar command that makes a new package in a new directory instead. different vibe, same family 🫢

πŸ’… OPTIONS πŸ’…

πŸ”₯ Init Options

  • --bin β€” create a package with a binary target (src/main.rs). this is the default behavior, iykyk. πŸ‘‘
  • --lib β€” create a package with a library target (src/lib.rs). πŸ“š
  • --edition edition β€” specify the Rust edition to use. default is 2024. possible values: 2015, 2018, 2021, 2024. ⭐
  • --name name β€” set the package name. defaults to the directory name. (so if your folder's called my-cool-thing, congrats, that's your package name πŸŽ€)
  • --vcs vcs β€” initialize a new VCS repository for the given version control system (git, hg, pijul, or fossil) β€” or don't initialize any version control at all (none). if not specified, it defaults to git, or the configuration value cargo-new.vcs, or none if you're already inside a VCS repository. 🌈
  • --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. πŸ’œ

🌈 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. πŸ—£οΈ
  • -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. 🀫
  • --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. 🎨

⭐ 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 at https://rust-lang.github.io/rustup/overrides.html for more information about how toolchain overrides work. πŸ¦€
  • --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 at https://doc.rust-lang.org/cargo/reference/config.html#command-line-overrides for more information. πŸ”§
  • -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.
⚠️ 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 at https://github.com/rust-lang/cargo/issues/10098). so like, not for the faint of heart fr fr.
  • -h, --help β€” prints help information. πŸ†˜
  • -Z flag β€” unstable (nightly-only) flags to Cargo. run cargo -Z help for details. πŸ™ˆ

🌸 ENVIRONMENT 🌸

see the reference at https://doc.rust-lang.org/cargo/reference/environment-variables.html for details on environment variables that Cargo reads. yes bestie, Cargo is nosy like that πŸ’œ


πŸŽ€ EXIT STATUS πŸŽ€

  • 0: Cargo succeeded. πŸŽ‰
  • 101: Cargo failed to complete. 😭

πŸ¦‹ EXAMPLES πŸ¦‹

  1. Create a binary Cargo package in the current directory:
cargo init

πŸ‘‘ SEE ALSO πŸ‘‘

cargo(1), cargo-new(1) β€” go read those too, they're iconic πŸ’–


and that's the whole page, bestie!! this was CARGO-INIT(1) from the General Commands Manual, signed off with love. now go cargo init something iconic and make it your whole personality βœ¨πŸ’…πŸ«Ά

πŸ“¦ where this page comes from