#cargo-toml #cargo #query #binary #dev-tools #cargo-subcommand

app cargo-get

Cargo plugin to easily query information from Cargo.toml files

11 releases (3 stable)

1.1.1 Feb 7, 2024
1.1.0 Oct 30, 2023
1.0.0 Aug 9, 2023
0.3.3 Oct 1, 2021
0.2.2 Oct 1, 2020

#57 in Cargo plugins

Download history 451/week @ 2024-01-03 644/week @ 2024-01-10 723/week @ 2024-01-17 854/week @ 2024-01-24 831/week @ 2024-01-31 912/week @ 2024-02-07 865/week @ 2024-02-14 970/week @ 2024-02-21 1032/week @ 2024-02-28 1185/week @ 2024-03-06 798/week @ 2024-03-13 1067/week @ 2024-03-20 815/week @ 2024-03-27 1045/week @ 2024-04-03 1001/week @ 2024-04-10 743/week @ 2024-04-17

3,860 downloads per month

Apache-2.0/MIT

28KB
536 lines

Cargo plugin to easily query information from Cargo.toml files

crates.io CI GitHub Release

Overview

This plugin helps querying information from a Cargo.toml file and can be used in shell scripts or CI/CD pipelines. The plugin accepts only one flag at a time and returns a single string with the requested value. Some queries like eq. keywords or authors return multiple values which get separated by line breaks (each value on a new line).

This plugin is inspired by cargo-edit and presents itself as a lightweight wrapper around cargo_toml

Contribution

Thanks for your interest - we gratefully welcome contributions.

Questions can be asked in issues. To help us help you get pull requests merged quickly and smoothly, open an issue before submitted large changes. Please keep the contents of pull requests and commits short. Commit messages should include the intent of the commit. cargo-get uses rustfmt for formatting and clippy for linting.

Installation

Pre-built Binaries

  1. Download the binary for your CPU architecture from the GitHub latest release.
  2. Make the binary executable using chmod +x
  3. Place the binary in your $PATH and rename it to cargo-get.

Cargo

Ensure that you have a fairly recent version of rust/cargo installed.

$ cargo install cargo-get

(Please check cargo's documentation to learn how cargo install works and how to set up your system so it finds binaries installed by cargo.)

Examples

All Options

$ cargo get -h
Cargo plugin to easily query information from Cargo.toml files

Usage: cargo-get [OPTIONS] <COMMAND>

Commands:
  package.name
  package.edition
  package.rust_version
  package.version
  package.build
  package.workspace
  package.authors
  package.links
  package.description
  package.homepage
  package.readme
  package.keywords
  package.categories
  package.exclude
  package.include
  package.license
  package.license_file
  package.repository
  package.default_run
  package.publish
  package.resolver
  package.metadata
  workspace.members
  workspace.package.authors
  workspace.package.categories
  workspace.package.description
  workspace.package.documentation
  workspace.package.edition
  workspace.package.exclude
  workspace.package.homepage
  workspace.package.include
  workspace.package.keywords
  workspace.package.license
  workspace.package.license_file
  workspace.package.publish
  workspace.package.readme
  workspace.package.repository
  workspace.package.rust_version
  workspace.package.version
  help                             Print this message or the help of the given subcommand(s)

Options:
      --entry <PATH>                                 Path to the crate root to query
      --delimiter <Tab | CR | LF | CRLF | String>    Delimiter for array values
      --terminator <CR | LF | CRLF | NUL | String>   String terminator for printed values. (Defaults to `LF`)
  -h, --help                                         Print help
  -V, --version                                      Print version

Get Version

$ cargo get package.version
0.2.1

$ cargo get package.version --pretty
v0.2.1

$ cargo get package.version --major --minor --patch --pre
0
2
1
alpha2

$ cargo get package.version --major --minor --delimiter="."
0.2

Now it is also easy to run commands like:

git tag $(cargo get package.version --pretty)

Get keywords

$ cargo get package.keywords
command-line-utilities
development-tools::cargo-plugins

Custom delimiter

# Use one of Tab, CR, LF, CRLF or a custom string.

$ cargo get package.keywords --delimiter Tab
command-line-utilities 	development-tools::cargo-plugins

$ cargo get package.keywords --delimiter=" -- "
command-line-utilities -- development-tools::cargo-plugins

$ cargo get package.keywords --delimiter=";"
command-line-utilities;development-tools::cargo-plugins

Optional entry point

# Full path
$ cargo get package.name --entry="../../some/other/project/Cargo.toml"
some-other-project

# Directory
$ cargo get package.name --entry="../../some/other/project"
some-other-project

# Current directory
$ cargo get package.name
current-project

GitHub Actions

Package name

- name: Get package name
  id: cargo-get
  uses: nicolaiunrein/cargo-get@master
  with:
    subcommand: package.name

Package author

- name: Get package author
  id: cargo-get
  uses: nicolaiunrein/cargo-get@master
  with:
    subcommand: package.authors

Dependencies

~1.7–2.4MB
~47K SLoC