Skip to content

Commit

Permalink
Merge pull request #5 from x807x/main
Browse files Browse the repository at this point in the history
use dirs::home instead of expanduser
  • Loading branch information
qtfkwk authored Feb 5, 2025
2 parents 8ae128f + ab66bce commit 2d6a421
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 113 deletions.
143 changes: 37 additions & 106 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = [ "development-tools::cargo-plugins", "command-line-utilities" ]
anyhow = "1.0.95"
clap = { version = "4.5.27", features = ["derive", "wrap_help"] }
clap-cargo = "0.15.2"
expanduser = "1.2.2"
dirs = "6.0.0"
indexmap = { version = "2.7.1", features = ["rayon"] }
lazy_static = "1.5.0"
rayon = "1.10.0"
Expand Down
19 changes: 16 additions & 3 deletions src/bin/cargo-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use clap::{
builder::{Styles, TypedValueParser},
Parser, ValueEnum,
};
use expanduser::expanduser;
use dirs::home_dir;
use indexmap::IndexSet;
use rayon::prelude::*;
use spinners::{Spinner, Spinners};
use sprint::*;
use std::collections::BTreeMap;
use std::{collections::BTreeMap, path::PathBuf};
use veg::colored::{ColoredString, Colorize, Veg};

#[cfg(unix)]
Expand Down Expand Up @@ -220,10 +220,23 @@ fn main() -> Result<()> {
inner(&cli)
}

fn extenduser(path: &str) -> PathBuf {
if path == "~" {
home_dir().unwrap().join(&path[1..])
}
else if path.starts_with("~") {
home_dir().unwrap().join(&path[2..])
}
else {
PathBuf::from(&path)
}
}
fn inner(cli: &List) -> Result<()> {
let mut sp = Spinner::new(Spinners::Line, "".into());


let installed = Crates::from_include(
&expanduser(&cli.config)?,
&extenduser(&cli.config),
&cli.include.iter().map(|x| x.as_str()).collect::<Vec<_>>(),
)?;
sp.stop();
Expand Down
6 changes: 3 additions & 3 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use cargo_list::Crates;
use expanduser::expanduser;
use dirs::home_dir;
use rayon::prelude::*;
use std::collections::BTreeMap;

#[test]
fn crates_from() {
let path = expanduser("~/.cargo/.crates2.json").unwrap();
let path = home_dir().unwrap().join(".cargo/.crates2.json");

match Crates::from(&path) {
Ok(installed) => {
Expand Down Expand Up @@ -52,7 +52,7 @@ fn crates_from() {

#[test]
fn crates_from_include() {
let path = expanduser("~/.cargo/.crates2.json").unwrap();
let path = home_dir().unwrap().join(".cargo/.crates2.json");

match Crates::from_include(&path, &["^t"]) {
Ok(installed) => {
Expand Down

0 comments on commit 2d6a421

Please sign in to comment.