Skip to content

Commit

Permalink
feat: add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Mar 15, 2024
1 parent f079076 commit 866537d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ readme = "README.md"
walkdir = "2.5.0"
cargo_metadata = "0.18.1"
cargo_toml = "0.19.2"
bpaf = { version = "0.9.9", features = ["derive"] }
syn = { version = "2", features = ["full", "visit"] }
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ Detect and remove unused dependencies from `Cargo.toml` in Rust projects.
* can we run some other command and get the macro expanded source to parse?
* is there an API for getting imports instead of parsing?

## Improvements

* add a CLI, preferably [bpaf](https://docs.rs/bpaf/latest/bpaf/index.html)
* make the reporting more granular for `[dependencies]`, `[dev-dependencies]` and `[build-dependencies]`
## TODO

- [ ] make the reporting more granular for `[dependencies]`, `[dev-dependencies]` and `[build-dependencies]`
- [ ] `--fix`
- [ ] add tests
- [ ] exit codes
- [ ] error recovery
- [ ] print things more nicely

## Prior Arts

Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ run-release command:
fmt:
cargo fmt
taplo format

lint:
cargo clippy
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
use std::{
collections::HashSet,
env, fs,
fs,
path::{Path, PathBuf},
};

use bpaf::Bpaf;
use cargo_metadata::{Metadata, MetadataCommand, Package};
use walkdir::WalkDir;

type Deps = HashSet<String>;

pub fn shear() {
let current_dir = env::args().nth(1).map_or_else(|| PathBuf::from("."), PathBuf::from);
#[derive(Debug, Clone, Bpaf)]
#[bpaf(options)]
pub struct Options {
#[bpaf(positional("PATH"), fallback(PathBuf::from(".")))]
path: PathBuf,
}

let metadata = MetadataCommand::new().current_dir(&current_dir).exec().unwrap();
pub fn shear(options: &Options) {
let metadata = MetadataCommand::new().current_dir(&options.path).exec().unwrap();
let workspace_root = metadata.workspace_root.as_std_path();

for package in metadata.workspace_packages() {
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use cargo_shear::shear;

use cargo_shear::options;

fn main() {
shear();
let options = options().fallback_to_usage().run();
shear(&options);
}

0 comments on commit 866537d

Please sign in to comment.