Giter Club home page Giter Club logo

cargo-wipe's Introduction

Cargo Wipe

Crates CI codecov license Crates.io
Cargo subcommand that recursively finds and optionally wipes all "target" or "node_modules" folders that are found in the current path.

Usage

Install

The Rust toolchain is a prerequisite.

cargo install cargo-wipe

Read the docs

cargo wipe --help

Use

To find build folders for <language> that can potentially be deleted run

cargo wipe <language>

where <language> is rust or node. For example:

cargo wipe rust

This will run in dry-run mode and just print the list of directories to delete. To actually delete them run it again with the -w flag.

cargo wipe rust -w

Directories are found according to the following logic:

  • rust: all directories called target containing a file called .rustc_info.json.
  • node: all directories called node_modules.

You can use the -i <path> argument to ignore certain paths.

Usage Example

Usage Example Screenshot

Contributions

Contributions are welcome and encouraged! See /issues for ideas, or suggest your own! If you're thinking to create a PR with large feature/change, please first discuss it in an issue.

PR Checks

    cargo make ci-flow

Releases

  • Update version in Cargo.toml

  • Update CHANGELOG.md

  • Commit

  • Add tag

    git tag -a vX.X.X
  • Push

    git push --follow-tags
  • Release
    Create a new release.
    publish.yml GitHub Action will pick it up and do the actual release to crates.io.

cargo-wipe's People

Contributors

atezet avatar dependabot[bot] avatar mihai-dinculescu avatar radicalzephyr avatar timmmm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cargo-wipe's Issues

Support Other Languages Build Directories

I noticed on the TODO page that there are currently no plans to support the build systems of any other languages. Would pull requests adding additional support be accepted?

Feature suggestion: --dry-run

Please consider adding a --dry-run flag that will find, list, summarize but not delete the target folders that will be deleted by cargo wipe if not run with the --dry-run flag.

The summary could include the number of files and size on disk that will be recovered.

-w all

would be nice to do node and target dir at once.

Get rid of aliases

The target and node_modules aliases are more confusing than helpful. rust and node are enough imho.

We should get rid of the target and node_modules aliases in all the documentation. However, they should continue working for a few more versions so that we don't break existing commands that people might be usings.

Dry run gives wrong help

Just ran cargo wipe rust for a dry run. At the end, the message displayed reads Run cargo wipe target -w to wipe all folders found. USE WITH CAUTION!

I'm assuming it's supposed to recommend cargo wipe rust -w?

The "target" folder is not wiped if it contains a "rls" folder

Running cargo wipe target -w removes the debug/release folders in target, but the rls folder (created by the Rust Language Server -- I use VS Code) is left untouched, so the target folder is not wiped in the end:

rust
├─ guessing_game
│  ├─ src
│  └─ target
│     └─ rls
│        └─ ...
└─ hello_cargo
   └─ src

Is this the intended behavior? Thank you!

RUSTSEC-2021-0139: ansi_term is Unmaintained

ansi_term is Unmaintained

Details
Status unmaintained
Package ansi_term
Version 0.12.1
URL ogham/rust-ansi-term#72
Date 2021-08-18

The maintainer has adviced this crate is deprecated and will not
receive any maintenance.

The crate does not seem to have much dependencies and may or may not be ok to use as-is.

Last release seems to have been three years ago.

Possible Alternative(s)

The below list has not been vetted in any way and may or may not contain alternatives;

See advisory page for additional details.

Allow the loading of a list of ignored paths from file

Currently one or more paths can be ignored by using the -i flag.

cargo wipe rust -i /home/user/path1 -i /home/user/path2

It would be most useful if these paths can be loaded from a file

cargo wipe rust -i /home/user/paths_to_ignore.txt

/home/user/paths_to_ignore.txt can contain one or more paths separated by new lines

/home/user/path1
/home/user/path2

This can be easily achieved by checking if the path given to the -i flag is a directory or a file.
If it's a directory, just ignore it. If it's a file, attempt to open it as text and parse the paths inside.

Interactive mode

It might be useful to offer an interactive mode so that the user can decide which folders to wipe on the fly.

Exclude recently modified folders

It sounds useful to have a flag that allows the exclusion of recently modified folders from the wipe (e.g. -d 30 will wipe everything that hasn't been touched in 30 days).

Re-architect options to be more pluggable

Re-architecting the current implementation to allow a more pluggable language listing could make for easier contributions.

Perhaps something like a list of defined regex matches for a Language option could allow for more language flexibility. This could be serializable and read from a config file, with a sane programmed default config file that is auto-generated.

use regex::Regex;
use serde::{Serialize, Deserialize};
use serde_regex; // Helper to serialize and deserialize RegEx

#[derive(Debug, Serialize, Deserialize)]
struct LanguageOption {
    /// The name of the language option. 
    option_name: String

    /// The RegEx that matches the target folder to be removed
    #[serde(with = "serde_regex")]
    target_folder_regexp: Regex,
    /// The optional RegEx that matches what the target folder must contain
    #[serde(with = "serde_regex")]
    target_folder_contains_regexp: Option<Regex>, //Maybe a list of Regex entries instead for multiple files
    /// The optional RegEx that matches what the target folder's parent must contain
    #[serde(with = "serde_regex")]
    parent_folder_contains_regexp: Option<Regex>, //Maybe a list of regex entries instead for multiple files
}

As seen above, adding serialization options for this allows these language options to be read from an external config (need appropriate serde_json or alike crate), which means users could add their own rules and options to this command.

Additionally, I imagined some additional struct fields for adding items that the target folder must contain, along with the parent folder. I think this might help alleviate #15

Example config:

[
  {
    "optionName": "MyWeirdEsotericLanguage",
    "targetFolderRegexp": "/someregex/",
    "targetFolderContainsRegexp": "/somefile/"
  }
]

or perhaps instead with multiple matches:

[
  {
    "optionName": "MyWeirdEsotericLanguage",
    "targetFolderRegexp": [
      "/someregex/",
      "/someotherregex/"
    ],
    "targetFolderContainsRegexp": [
      "/somefile/",
      "/someotherfile/"
    ]
  }
]

I think this would increase complexity about where to store the config and be cross platform (not sure if cross-platform is a goal currently), but would allow for that flexibility increase.

If I get some time, maybe I'll entertain a PR with an implementation of this :)

[Question] is file_count correct ?

hey, I meet a proble, here is a directory vue-frontend, and when calling cargo wipe node in the directory
image

but when I call the find . type f | wc -l
image

the file_counts are not the same at all,

I have some function that modify from your code,

pub fn dir_size(path: impl Into<PathBuf>) -> io::Result<DirInfo> {
    let mut visited = HashSet::new();
    dir_size_0(path, &mut visited)
}

fn dir_size_0(path: impl Into<PathBuf>, visited: &mut HashSet<String>) -> io::Result<DirInfo> {
    let mut dir_info = DirInfo::new(0, 0, 0);

    let targetpath: PathBuf = path.into();
    for entry in WalkDir::new(&targetpath).max_depth(1) {
        let entry = entry?;
        let filepath = entry.path().display().to_string();

        if filepath == "." || filepath == "./" || filepath == targetpath.display().to_string() {
            continue;
        }

        if entry.file_type().is_dir() && !visited.contains(&filepath) {
            visited.insert(filepath.clone());
            let child_dir_info = dir_size_0(&filepath, visited)?;
            dir_info.dir_count += child_dir_info.dir_count + 1;
            dir_info.file_count += child_dir_info.file_count;
            dir_info.size += child_dir_info.size;
        } else {
            let file = File::open(&filepath)?;
            let metadata = file.metadata()?;
            dir_info.file_count += 1;
            dir_info.size += metadata.len() as usize;
        }
        
    }

    Ok(dir_info)
}

and the test resuls is
image

I am a little confused now, what is the matter with my code, or your code ?

Show the real directory size on disk

Currently, there is a slight inconsistency between the size shown by cargo-wipe and the real size shown on the disk. It would be lovely if we can fix this.

Is there any plans to go out of Cargo wipe ?

I am experimenting with rust and so do may users of this library. But is there any plans to move out cargo and go as separate install?

like brew for mac, choco for Windows ? I guess this utility can help and serve many developers around the spectrum.

PS: Full stack developer working with node can be benefited from if this is served without cargo. Again this is my personal two cents. I am OK with using it with cargo.

I was looking for something similar since ages. Thanks for great tool chain.

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.