Skip to content

Commit

Permalink
Add project version {major,minor,patch} CLIs (#633)
Browse files Browse the repository at this point in the history
See context at #581
  • Loading branch information
hadim authored Jan 9, 2024
1 parent f642df3 commit c9d097c
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
108 changes: 108 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions src/cli/project/version/bump.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
11 changes: 11 additions & 0 deletions src/cli/project/version/mod.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<()> {
Expand All @@ -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(())
Expand Down

0 comments on commit c9d097c

Please sign in to comment.