Skip to content

cargo new should allow me to set the default package version #16948

@dradetsky

Description

@dradetsky

Problem

Currently, if I run cargo new mypkg it creates Cargo.toml with version set to 0.1.0. This appears to be because we hardcode this version in https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_new.rs#L801. I would like to be able to configure cargo to use a different default version.

Proposed Solution

Add a field to the cargo configuration file

[cargo-new]
version = '1.0.0'

If present, cargo new mypkg would be created with the version set to 1.0.0. Otherwise, we would default to creating packages at 0.1.0.

Notes

Hopefully, we can just ignore questions like "Should we allow the user to set the initial version with a flag? Or an env var?" My feeling is: set-by-config is the only thing I want in terms of an actuall feature I want to use, as opposed to something to be added for completeness/consistency. If for some reason I really need to programmatically create packages with a specified version, I can hack something together with project-local config files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-initCommand-newS-triageStatus: This issue is waiting on initial triage.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions