From c9d097c941e718e0576f2869fc50de57514a0c4a Mon Sep 17 00:00:00 2001 From: Hadrien Mary Date: Tue, 9 Jan 2024 13:50:01 -0500 Subject: [PATCH] Add `project version {major,minor,patch}` CLIs (#633) See context at https://github.com/prefix-dev/pixi/issues/581 --- docs/cli.md | 108 ++++++++++++++++++++++++++++++++ src/cli/project/version/bump.rs | 34 ++++++++++ src/cli/project/version/mod.rs | 11 ++++ 3 files changed, 153 insertions(+) create mode 100644 src/cli/project/version/bump.rs diff --git a/docs/cli.md b/docs/cli.md index c9d839281..cbd911c0b 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -393,6 +393,114 @@ pixi project channel add https://repo.prefix.dev/conda-forge pixi project channel add --no-install robostack ``` +### `project channel list` + +List the channels in the project file + +##### Options + +- `--no-install`: do not update the environment, only add changed packages to the lock-file. + +```sh +$ pixi project channel list +conda-forge +$ pixi project channel list --urls +https://conda.anaconda.org/conda-forge/ +``` + +### `project channel remove` + +List the channels in the project file + +##### Options + +- `--no-install`: do not update the environment, only add changed packages to the lock-file. + +```sh +pixi project channel remove conda-forge +pixi project channel remove https://conda.anaconda.org/conda-forge/ +``` + +### `project description get` + +Get the project description. + +```sh +$ pixi project description get +Package management made easy! +``` + +### `project description set` + +Set the project description. + +```sh +pixi project description set "my new description" +``` + +### `project platform add` + +Adds a platform(s) to the project file and updates the lockfile. + +##### Options + +- `--no-install`: do not update the environment, only add changed packages to the lock-file. + +```sh +pixi project platform add win-64 +``` + +### `project platform list` + +List the platforms in the project file. + +```sh +$ pixi project platform list +osx-64 +linux-64 +win-64 +osx-arm64 +``` + +### `project platform remove` + +Remove platform(s) from the project file and updates the lockfile. + +##### Options + +- `--no-install`: do not update the environment, only add changed packages to the lock-file. + +```sh +pixi project platform remove win-64 +``` + +### `project version get` + +Get the project version. + +```sh +$ pixi project version get +0.11.0 +``` + +### `project version set` + +Set the project version. + +```sh +pixi project version set "0.12.0" +``` + +### `project version {major|minor|patch}` + +Bump the project version to {MAJOR|MINOR|PATCH}. + +```sh +pixi project version major +pixi project version minor +pixi project version patch +``` + [^1]: An __up-to-date__ lockfile means that the dependencies in the lockfile are allowed by the dependencies in the manifest file. For example diff --git a/src/cli/project/version/bump.rs b/src/cli/project/version/bump.rs new file mode 100644 index 000000000..399cbc15f --- /dev/null +++ b/src/cli/project/version/bump.rs @@ -0,0 +1,34 @@ +use crate::Project; +use miette::{Context, IntoDiagnostic}; +use rattler_conda_types::VersionBumpType; + +pub async fn execute(mut project: Project, bump_type: VersionBumpType) -> miette::Result<()> { + // get version and exit with error if not found + let current_version = project + .version() + .as_ref() + .ok_or_else(|| miette::miette!("No version found in manifest."))? + .clone(); + + // bump version + let new_version = current_version + .bump(bump_type) + .into_diagnostic() + .context("Failed to bump version.")?; + + // Set the version + project.manifest.set_version(&new_version.to_string())?; + + // Save the manifest on disk + project.save()?; + + // Report back to the user + eprintln!( + "{}Updated project version from '{}' to '{}'.", + console::style(console::Emoji("✔ ", "")).green(), + current_version, + new_version, + ); + + Ok(()) +} diff --git a/src/cli/project/version/mod.rs b/src/cli/project/version/mod.rs index 0e6505912..c30950ad9 100644 --- a/src/cli/project/version/mod.rs +++ b/src/cli/project/version/mod.rs @@ -1,8 +1,10 @@ +pub mod bump; pub mod get; pub mod set; use crate::Project; use clap::Parser; +use rattler_conda_types::VersionBumpType; use std::path::PathBuf; /// Commands to manage project description. @@ -23,6 +25,12 @@ pub enum Command { Get(get::Args), /// Set the project version. Set(set::Args), + /// Bump the project version to MAJOR. + Major, + /// Bump the project version to MINOR. + Minor, + /// Bump the project version to PATCH. + Patch, } pub async fn execute(args: Args) -> miette::Result<()> { @@ -31,6 +39,9 @@ pub async fn execute(args: Args) -> miette::Result<()> { match args.command { Command::Get(args) => get::execute(project, args).await?, Command::Set(args) => set::execute(project, args).await?, + Command::Major => bump::execute(project, VersionBumpType::Major).await?, + Command::Minor => bump::execute(project, VersionBumpType::Minor).await?, + Command::Patch => bump::execute(project, VersionBumpType::Patch).await?, } Ok(())