51 releases (26 breaking)

new 0.27.0 Dec 5, 2024
0.26.0 Oct 25, 2024
0.25.1 Jul 30, 2024
0.24.1 Mar 11, 2024
0.7.0 May 24, 2023

#117 in Cargo plugins

Download history 142/week @ 2024-08-17 43/week @ 2024-08-24 28/week @ 2024-08-31 17/week @ 2024-09-07 15/week @ 2024-09-14 61/week @ 2024-09-21 11/week @ 2024-09-28 13/week @ 2024-10-05 15/week @ 2024-10-12 136/week @ 2024-10-19 64/week @ 2024-10-26 49/week @ 2024-11-02 9/week @ 2024-11-09 28/week @ 2024-11-16 23/week @ 2024-11-23 275/week @ 2024-11-30

348 downloads per month

MIT and CC-PDDC licenses

36KB
726 lines

Usage

CLI

$ cargo list -h
List and update installed crates

Usage: cargo list [OPTIONS] [PATTERN]...

Arguments:
  [PATTERN]...  List/update crates matching given pattern(s)

Options:
  -f <FORMAT>      Output format [default: md] [possible values: json,
                   json-pretty, md, rust, rust-pretty]
  -k <KIND>        Kind(s) [default: external] [possible values: local, git,
                   external]
  -a               All kinds
  -o, --outdated   Hide up-to-date crates
  -I               Ignore version requirements
  -R               Consider a crate to be outdated if compiled with a Rust
                   version different than the active toolchain
  -u, --update     Update outdated crates
  -n, --dry-run    Dry run
  -c <PATH>        Cargo install metadata file [default: ~/.cargo/.crates2.json]
  -r, --readme     Print readme
  -h, --help       Print help
  -V, --version    Print version
$ cargo list -V
cargo-list 0.27.0

List installed external crates

cargo list

List installed external crates containing cargo

cargo list cargo

List installed external crates beginning with cargo

cargo list ^cargo

List installed external crates ending with list

cargo list 'list$'

List installed external crates matching cargo-list

cargo list '^cargo-list$'

List outdated external crates

cargo list -o

Update outdated external crates

cargo list -ou

List the cargo install commands to update outdated external crates

cargo list -oun

List outdated external crates (ignore version requirements)

cargo list -oI

List outdated external crates (include crates compiled with old Rust)

cargo list -oR

Update outdated external crates (ignore version requirements and include crate compiled with old Rust)

cargo list -oIRu

List crates installed via git

cargo list -k git

List installed local crates

cargo list -k local

List installed local, git, and external crates

cargo list -k local -k git -k external

or shorter:

cargo list -a

List outdated crates installed via git

cargo list -k git -o

List outdated installed local crates

cargo list -k local -o

List outdated installed local, git, and external crates

cargo list -k local -k git -k external -o

or shorter:

cargo list -ao

Dump installed external crates to JSON

cargo list -f json

Dump installed external crates to pretty JSON

cargo list -f json-pretty

Dump installed external crates to Rust

cargo list -f rust

Dump installed external crates to pretty Rust

cargo list -f rust-pretty

Dump outdated installed external crates to JSON

cargo list -f json -o

Dump outdated installed external crates to pretty JSON

cargo list -f json-pretty -o

Dump outdated installed external crates to Rust

cargo list -f rust -o

Dump outdated installed external crates to pretty Rust

cargo list -f rust-pretty -o

Library

use cargo_list::Crates;
use expanduser::expanduser;
use rayon::prelude::*;
use std::collections::BTreeMap;

let path = expanduser("~/.cargo/.crates2.json").unwrap();

match Crates::from(&path) {
    Ok(installed) => {
        if installed.is_empty() {
            println!("No crates installed!");
        } else {
            let all = installed.crates();
            let outdated = all
                .par_iter()
                .filter_map(|(&name, &c)| c.outdated.then_some((name, c)))
                .collect::<BTreeMap<_, _>>();

            if outdated.is_empty() {
                // List all crates in CSV
                println!("Name,Installed");
                for (name, c) in &all {
                    println!("{name},{}", c.installed);
                }
            } else {
                // List outdated crates in CSV
                println!("Name,Installed,Available");
                for (name, c) in &outdated {
                    println!("{name},{},{}", c.installed, c.available);
                }

                // Print the `cargo install` commands for outdated crates
                // for command in outdated
                //     .iter()
                //     .map(|(_name, c)| c.update_command().join(" "))
                // {
                //     println!("{command}");
                // }

                // Update outdated crates
                // outdated.iter().for_each(|(_name, c)| c.update());
            }
        }
    }
    Err(e) => {
        eprintln!("Error: {e}");
    }
}

If you want to include just a subset of the crates, instead of Crates::from(&path), use Crates::from_include(&path, &patterns) where patterns is a slice of &str regex patterns.

Changelog

Please read the CHANGELOG.md in the repository.

Dependencies

~15–30MB
~487K SLoC