Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dfinity/dfxvm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f3a159e194e5b386509795c5c2088f4b0d9c08ab
Choose a base ref
...
head repository: dfinity/dfxvm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5e887d483bf99b7cbe8ef88edc06b0bc15cd7dee
Choose a head ref
  • 2 commits
  • 12 files changed
  • 1 contributor

Commits on Dec 12, 2024

  1. fix: update reqwest and url to fix the cargo audit error. (#93)

    * Update reqwest and url to fix the cargo audit error.
    
    * Allow 'Unicode-3.0' license.
    vincent-dfinity authored Dec 12, 2024
    Copy the full SHA
    064eb9b View commit details
  2. feat: dfxvm --list now supports listing the remote available dfx ve…

    …rsions. (#89)
    
    * Add support for listing the remote available dfx versions.
    
    * Add a test for listing remote versions.
    
    * Fixed lint.
    
    * Address review comments.
    
    * Fixed the review comments.
    
    * Improved the wordings.
    
    * Update dfxvm list document.
    
    * Trigger build.
    vincent-dfinity authored Dec 12, 2024
    Copy the full SHA
    5e887d4 View commit details
Showing with 1,026 additions and 432 deletions.
  1. +4 −0 CHANGELOG.md
  2. +873 −402 Cargo.lock
  3. +2 −2 Cargo.toml
  4. +2 −1 deny.toml
  5. +46 −2 docs/cli-reference/dfxvm/dfxvm-list.mdx
  6. +1 −0 src/dfxvm.rs
  7. +11 −3 src/dfxvm/cli.rs
  8. +26 −9 src/dfxvm/list.rs
  9. +13 −0 src/dfxvm/manifest.rs
  10. +1 −12 src/dfxvm/update.rs
  11. +6 −0 src/error/dfxvm.rs
  12. +41 −1 tests/suite/dfxvm/list.rs
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

- `dfxvm --list` now supports listing the available dfx versions.
- `--available`: List the available versions.
- `--limit`: The maximum number of available versions to list in reverse chronological order, with default value `10`.

## [1.0.0] - 2024-02-20

## [0.3.1] - 2024-02-07
1,275 changes: 873 additions & 402 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ futures-util = "0.3.14"
hex = "0.4.3"
indicatif = "0.15.0"
itertools = "0.11.0"
reqwest = { version = "0.11.22", default_features = false, features = [ "stream", "rustls-tls" ] }
reqwest = { version = "0.12.9", default_features = false, features = [ "stream", "rustls-tls" ] }
semver = { version = "1.0", features = [ "serde" ] }
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
@@ -32,7 +32,7 @@ tar = "0.4.40"
tempfile = "3"
thiserror = "1.0"
tokio = { version = "1.34", features = ["macros"] }
url = "2.4"
url = "2.5"

[dev-dependencies]
assert_cmd = "2.0"
3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ allow = [
"MIT",
"MPL-2.0",
"Zlib",
"Unicode-DFS-2016"
"Unicode-DFS-2016",
"Unicode-3.0",
]

deny = [
48 changes: 46 additions & 2 deletions docs/cli-reference/dfxvm/dfxvm-list.mdx
Original file line number Diff line number Diff line change
@@ -4,12 +4,16 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow";

<MarkdownChipRow labels={["Reference"]} />

Lists the installed versions of dfx.
List installed or available versions of dfx.

## Usage

```bash
dfxvm list
dfxvm list [OPTIONS]

Options:
--available List the available versions
--limit <LIMIT> The maximum number of available versions to list, in reverse chronological order [default: 10]
```

## Examples
@@ -20,3 +24,43 @@ $ dfxvm list
0.15.1 (default)
0.15.2-beta.1
```

```bash
$ dfxvm list --available
info: fetching https://sdk.dfinity.org/manifest.json
0.24.3
0.24.2
0.24.1
0.24.0
0.23.0
0.22.0
0.21.0
0.20.1
0.20.0
0.19.0
```

```bash
$ dfxvm list --available --limit 20
info: fetching https://sdk.dfinity.org/manifest.json
0.24.3
0.24.2
0.24.1
0.24.0
0.23.0
0.22.0
0.21.0
0.20.1
0.20.0
0.19.0
0.18.0
0.17.0
0.16.1
0.16.0
0.15.3
0.15.2
0.15.1
0.15.0
0.14.4
0.14.3
```
1 change: 1 addition & 0 deletions src/dfxvm.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ mod cli;
mod default;
mod install;
mod list;
mod manifest;
mod self_uninstall;
mod self_update;
mod uninstall;
14 changes: 11 additions & 3 deletions src/dfxvm/cli.rs
Original file line number Diff line number Diff line change
@@ -42,9 +42,17 @@ pub struct DefaultOpts {
version: Option<Version>,
}

/// List installed versions of dfx
/// List installed or available versions of dfx
#[derive(Parser)]
pub struct ListOpts {}
pub struct ListOpts {
/// List the available versions.
#[arg(long)]
pub available: bool,

/// The maximum number of available versions to list, in reverse chronological order.
#[arg(long, default_value_t = 10, requires("available"))]
pub limit: usize,
}

/// Uninstall a version of dfx
#[derive(Parser)]
@@ -89,7 +97,7 @@ pub async fn main(args: &[OsString], locations: &Locations) -> Result<ExitCode,
match cli.command {
Command::Default(opts) => default(opts.version, locations).await?,
Command::Install(opts) => install(opts.version, locations).await?,
Command::List(_opts) => list(locations)?,
Command::List(opts) => list(opts, locations).await?,
Command::SelfCmd(opts) => match opts.command {
SelfCommand::Update(_opts) => self_update(locations).await?,
SelfCommand::Uninstall(opts) => self_uninstall(opts.yes, locations)?,
35 changes: 26 additions & 9 deletions src/dfxvm/list.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
use crate::dfxvm::cli::ListOpts;
use crate::dfxvm::manifest::Manifest;
use crate::error::dfxvm::ListError;
use crate::json::fetch_json;
use crate::locations::Locations;
use crate::settings::Settings;
use itertools::Itertools;
use reqwest::Url;
use semver::Version;

pub fn list(locations: &Locations) -> Result<(), ListError> {
pub async fn list(opts: ListOpts, locations: &Locations) -> Result<(), ListError> {
let settings = Settings::load_or_default(&locations.settings_path())?;
let default_version = settings.default_version;
if opts.available {
let url = Url::parse(&settings.manifest_url())?;

for version in installed_versions(locations)? {
let default_indicator = if default_version.as_ref() == Some(&version) {
" (default)"
} else {
""
};
println!("{}{}", version, default_indicator);
info!("fetching {url}");
let manifest = fetch_json::<Manifest>(&url).await?;

let count = std::cmp::min(opts.limit, manifest.versions.len());
let versions = manifest.versions.iter().rev().take(count);
for version in versions {
println!("{}", version);
}
} else {
let default_version = settings.default_version;

for version in installed_versions(locations)? {
let default_indicator = if default_version.as_ref() == Some(&version) {
" (default)"
} else {
""
};
println!("{}{}", version, default_indicator);
}
}
Ok(())
}
13 changes: 13 additions & 0 deletions src/dfxvm/manifest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use semver::Version;
use serde::Deserialize;

#[derive(Deserialize)]
pub struct Tags {
pub latest: Version,
}

#[derive(Deserialize)]
pub struct Manifest {
pub tags: Tags,
pub versions: Vec<Version>,
}
13 changes: 1 addition & 12 deletions src/dfxvm/update.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::dfxvm::default::set_default;
use crate::dfxvm::manifest::Manifest;
use crate::error::dfxvm::UpdateError;
use crate::json::fetch_json;
use crate::locations::Locations;
use crate::settings::Settings;
use reqwest::Url;
use semver::Version;
use serde::Deserialize;

pub async fn update(locations: &Locations) -> Result<(), UpdateError> {
let settings = Settings::load_or_default(&locations.settings_path())?;
@@ -21,13 +20,3 @@ pub async fn update(locations: &Locations) -> Result<(), UpdateError> {

Ok(())
}

#[derive(Deserialize)]
struct Tags {
latest: Version,
}

#[derive(Deserialize)]
struct Manifest {
tags: Tags,
}
6 changes: 6 additions & 0 deletions src/error/dfxvm.rs
Original file line number Diff line number Diff line change
@@ -46,9 +46,15 @@ pub enum Error {

#[derive(Error, Debug)]
pub enum ListError {
#[error(transparent)]
FetchVersions(#[from] FetchJsonDocError),

#[error(transparent)]
LoadJsonFile(#[from] LoadJsonFileError),

#[error("failed to parse manifest url")]
ParseManifestUrl(#[from] url::ParseError),

#[error("failed to read directory {path}")]
ReadDir {
path: PathBuf,
42 changes: 41 additions & 1 deletion tests/suite/dfxvm/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::common::TempHomeDir;
use crate::common::file_contents::manifest_json;
use crate::common::{ReleaseServer, TempHomeDir};
use assert_cmd::prelude::*;
use predicates::str::*;
use std::fs::create_dir_all;

#[test]
@@ -87,3 +89,41 @@ fn ignores_non_versions() {
.success()
.stdout("0.3.2\n0.7.1\n0.14.2\n0.15.0-beta.1\n");
}

#[test]
fn remote_versions() {
let home_dir = TempHomeDir::new();
let server = ReleaseServer::new(&home_dir);

server.expect_get_manifest(&manifest_json("0.14.6"));

home_dir
.dfxvm()
.arg("list")
.arg("--available")
.assert()
.success()
.stderr(is_match("info: fetching http://.*/manifest.json").unwrap())
.stdout(contains("0.5.2").count(1))
.stdout(contains("0.5.0").count(1));
}

#[test]
fn remote_versions_with_limit() {
let home_dir = TempHomeDir::new();
let server = ReleaseServer::new(&home_dir);

server.expect_get_manifest(&manifest_json("0.14.6"));

home_dir
.dfxvm()
.arg("list")
.arg("--available")
.arg("--limit")
.arg("1")
.assert()
.success()
.stderr(is_match("info: fetching http://.*/manifest.json").unwrap())
.stdout(contains("0.5.2").count(1))
.stdout(contains("0.5.0").count(0));
}