GithubHelp home page GithubHelp logo

dohzoh / cargo-edit-locally Goto Github PK

View Code? Open in Web Editor NEW

This project forked from k0nserv/cargo-edit-locally

0.0 1.0 0.0 385 KB

Subcommand to easily edit crate dependencies locally

License: Apache License 2.0

Rust 100.00%

cargo-edit-locally's Introduction

cargo-edit-locally

Build Status Build status

This is a Cargo subcommand which intends to allow easy management of the [replace] section of Cargo.toml.

Installation

Currently this can be installed with:

$ cargo install cargo-edit-locally

You can also install precompiled binaries that are assembled on the CI for this crate.

Example Usage

After working on some Rust code for a bit let's say that we've got a dependency on the log crate on crates.io. We think we've found a bug in the log crate so we'd like to test out our findings and check it out. First, let's take a look at our $CODE/Cargo.toml:

[package]
name = "foo"
version = "0.1.0"

[dependencies]
log = "0.3"

Let's say we've got a checkout of log locally and we'd like to verify it fixes our bug:

$ cd $CODE
$ cargo edit-locally log --path ../log
$

And that's it! The local project, foo, is now configured to use the log folder in our local code directory. We can see that Cargo.toml now has a [[replace]][replace] section:

[replace]
'log:0.3.7' = { path = 'log' }

And finally can now use the log crate from our local build!

$ cargo build
   Compiling log v0.3.7 ($CODE/log)
   Compiling foo v0.1.0 ($CODE)
    Finished dev [unoptimized + debuginfo] target(s) in 1.97 secs

If we instead would like to test out a git repository we can use:

$ cargo edit-locally log --git https://github.com/rust-lang-nursery/log

To see a full suite of options available to you and another help message, execute:

$ cargo help edit-locally

Undoing local edits

To go back to using crates.io, you can simply delete the [replace] section in the manifest. This'll go back to using the version in the lock file, and the next cargo build will compile code from crates.io instead of your local folder.

After the [replace] section is deleted you can delete the folder of the checkout as well, after saving off your work if needed.

Caveats

This subcommand will automatically attempt to edit Cargo.toml and insert a [replace] section for you. Unfortunately there's no great robust way right now to edit TOML file preserving formatting and comments and such, so right now there's mostly just a few heuristics to do this automatically.

If you find that the heuristics don't work for you though please let me know and I'll try to check in a fix!

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

cargo-edit-locally's People

Contributors

alexcrichton avatar dependabot-preview[bot] avatar dependabot-support avatar manishearth avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.