Utility to inherit dependencies from workspace file if it occurs 'n' or more times throughout the project.

Overview

Cargo Workspace Dependency Inheritor

Utility that inherits dependencies from the main workspace if they occur n or more times in the workspace.

Workspace Inheritance was stabilized in version 1.64. See [workspace.package], [workspace.dependencies], and inheriting-a-dependency-from-a-workspace for more information.

How to Use

To inherit a dependency that occurs five or more times in the workspace, use the following command:

cargo install cargo-dependency-inheritor
cargo dependency-inheritor --workspace-path "path/to/workspace/Cargo.toml" -n 5

This command edits your toml files, make sure to have a back up

Process

Dependencies can be inherited from a workspace by specifying the dependency in the workspace's [workspace.dependencies] table. After that, add it to the [dependencies] table with workspace = true. This crate automates the process.

  1. Read packages defined in [workspace] section of the workspace-file.
  2. Note which dependencies occur n or more times.
  3. Update all dependencies that occurred n or more times:
    1. Turn dependency = "0.1.3" into inline tables.
    2. Add workspace = true key-value to the dependency inline table.
    3. Remove version from inline table if exists (this will be specified in the workspace file).
  4. Add [workspace.dependencies] table to root workspace file with all the dependencies that occurred n times and their version.

Result:

# in a project
[dependencies]
tokio = { workspace = true }

# in the workspace
[workspace.dependencies]
tokio = "1.0"
Comments
  • Inherit `default-features = false` from packages

    Inherit `default-features = false` from packages

    Depends on #8

    When packages are added to the workspace they seem to infer default features even if all workspace members disable default features: hence this flag must be propagated to the workspace dependencies list.

    It should not be necessary to inherit feature flags from individual crates though, as these are additive across the workspace (but it might be cleaner to strip all common feature flags?).

    opened by MarijnS95 4
  • Skip local dependencies with `path =` source

    Skip local dependencies with `path =` source

    These dependencies are typically part of a workspace and referred to with a path = "../some/crate" designator. Pointing to them through a workspace dependency is possible and maybe even more concise at the detriment of specifying them more often, but at least without removing path= from the per-crate dependencies causes havoc:

    Dependency 'foo' has different source paths depending on the build target. Each dependency must have a single canonical source path irrespective of build target.
    
    opened by MarijnS95 4
  • cargo subcommand doesn't invoke this program correctly

    cargo subcommand doesn't invoke this program correctly

    $ cargo +beta dependency-inherit -n 2
    error: no such subcommand: `dependency-inherit`
    
            Did you mean `dependency-inheritor`?
    
            View all installed commands with `cargo --list`
    
    $ cargo +beta dependency-inheritor -n 2
    error: The subcommand 'dependency-inheritor' wasn't recognized
    
            Did you mean 'dependency-inherit'?
    
    If you believe you received this message in error, try re-running with 'cargo -- dependency-inheritor'
    
    USAGE:
        cargo <SUBCOMMAND>
    
    For more information try --help
    
    $ cargo +beta --version
    cargo 1.65.0-beta.1 (082503982 2022-09-13)
    

    System is Windows 11 with MSVC target.

    opened by Xaeroxe 3
  • Fix

    Fix "subcommand wasn't recognized" when invoked under `cargo`

    Fixes #1

    Users are seeing:

    error: The subcommand 'dependency-inheritor' wasn't recognized
    
            Did you mean 'dependency-inherit'?
    

    This happens because the resulting exectuable is cargo-dependency-inheritor (this package name), which cargo invokes with dependency-inheritor as subcommand whereas the Cargo enum variant was expecting dependency-inherit (based on DependencyInherit).

    opened by MarijnS95 2
  • Fix table getting added as `[

    Fix table getting added as `["workspace.dependencies"]`

    toml_edit assumes the key needs to be taken literally here, and escapes the period (.) by inserting quotes (") around the entire key, while dependencies is instead a subtable of workspace.

    It is curious that get_mut() on such a key seems to work, though.

    opened by MarijnS95 0
  • Path dependencies shouldn't specify a version

    Path dependencies shouldn't specify a version

    Currently dependencies with a path attribute are also specifying a version when auto generated, i.e. version = "*". It's better to omit this, the only restriction it adds is that it prevents you from using pre-release versions of a crate that you have vendored in. This can result in the path attribute being ignored, leading to some very confusing builds.

    opened by Xaeroxe 0
  • Paths are being changed to use `\` instead of `/` on Windows

    Paths are being changed to use `\` instead of `/` on Windows

    Rust on Windows can correctly use / but Rust on Linux cannot correctly use \, so this tool should never output \ into a path attribute for a dependency.

    opened by Xaeroxe 0
Owner
Timon
Hakuna Matata
Timon
Zellij is a workspace aimed at developers, ops-oriented people and anyone who loves the terminal

Zellij is a workspace aimed at developers, ops-oriented people and anyone who loves the terminal. At its core, it is a terminal multiplexer (similar to tmux and screen), but this is merely its infrastructure layer.

null 9.3k Jan 4, 2023
A collection of tools for i3 that assist in window, workspace and output operations.

i3-valet A collection of tools for i3 that assist in window, workspace and output operations. i3-valet can be run directly from the command line or as

Erich Heine 15 Jan 8, 2023
A gui tool written in Dioxus to make it easy to release a workspace of crates to crates.io

Easy-Release: a visual tool for releasing workspaces of libraries A work-in-progress GUI for releasing a large workspace of crates manually, but easil

Jon Kelley 13 Jan 18, 2023
Simple and lightweight tray icon that shows the current workspace for the Komorebi window manager.

komotray Simple and lightweight tray icon that shows the current workspace for the Komorebi window manager. This is a Rust rewrite of the original Aut

Joshua Park 8 Sep 27, 2024
A utility for managing cargo dependencies from the command line.

cargo edit This tool extends Cargo to allow you to add, remove, and upgrade dependencies by modifying your Cargo.toml file from the command line. Curr

Pascal Hertleif 2.7k Jan 6, 2023
This utility traverses through your filesystem looking for open-source dependencies that are seeking donations by parsing README.md and FUNDING.yml files

This utility traverses through your filesystem looking for open-source dependencies that are seeking donations by parsing README.md and FUNDING.yml files

Mufeed VH 38 Dec 30, 2022
Get up-to-date departure times for Munich public transport in your terminal.

MVG Fahrinfo MVG Fahrinfo is a CLI tool to keep up-to-date with latest departure times of Munich public transport. The app is a native binary and uses

Faisal Bin Ahmed 70 Nov 14, 2023
A CLI tool that allow you to create a temporary new rust project using cargo with already installed dependencies

cargo-temp A CLI tool that allow you to create a new rust project in a temporary directory with already installed dependencies. Install Requires Rust

Yohan Boogaert 61 Oct 31, 2022
Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're working with files or directories, this tool simplifies common file operations with ease.

Rust FileOps Rust File Management CLI is a command-line tool written in Rust that provides essential file management functionalities. Whether you're w

Harikesh Ranjan Sinha 5 May 2, 2024
🧠 A command-line utility for switching git branches more easily. Switch branches interactively or use a fuzzy search to find that long-forgotten branch name.

git-smart-checkout A git command extension for switching git branches more efficiently. About Interactively switch branches or fuzzy search for that f

Cezar Craciun 51 Dec 29, 2022
An awesome CLI tool for effectively learning Rust and more. Project winner of the RustFi 2022 hackathon

rlrn An awesome CLI tool for effectively learning Rust and more Table of Contents About The Project Built With Getting Started Prerequisites Installat

Victor Kostyuk 6 Dec 25, 2022
A rust binary that will flip one or more bits of a file (mostly for messing with images for fun).

file-bitflipper A rust binary that will flip one or more bits of a file (mostly for messing with images for fun). Example (bitflipped bentley) Usage $

null 1 Aug 31, 2022
rpsc is a *nix command line tool to quickly search for file systems items matching varied criterions like permissions, extended attributes and much more.

rpsc rpsc is a *nix command line tool to quickly search for file systems items matching varied criterions like permissions, extended attributes and mu

null 3 Dec 15, 2022
A command-line utility that creates project structure.

petridish A command-line utility that creates project structure. If you have heard of the cookiecutter project, petridish is a rust implementation of

null 11 Dec 29, 2022
SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project.

SKYULL is a command-line interface (CLI) in development that creates REST API project structure templates with the aim of making it easy and fast to start a new project. With just a few primary configurations, such as project name, you can get started quickly.

Gabriel Michaliszen 4 May 9, 2023
A simple CLI tool to create python project file structure, written in Rust

Ezpie Create python projects blazingly fast What Ezpie can do? It can create a python project directory What kind of directory can Ezpie create? For c

Faseeh 3 Sep 29, 2023
Single File Assets is a file storage format for images

SFA (Rust) Single File Assets is a file storage format for images. The packed images are not guaranteed to be of same format because the format while

null 1 Jan 23, 2022
A command-line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the returned URL.

Pup A command line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the return

SteveLau 11 Aug 17, 2022
A tool for determining file types, an alternative to file

file-rs a tool for determining file types, an alternative to file whats done determining file extension determining file type determining file's mime

null 3 Nov 27, 2022