Skip to content

Commit

Permalink
big cleanup & re-focus
Browse files Browse the repository at this point in the history
  • Loading branch information
tbillington committed Jul 31, 2020
1 parent 6560c10 commit 7e76b65
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 203 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

- Remove all options and subcommands to re-focus the intent of Kondo
- Default is now interactive mode, allowing users to choose options on a per-project basis

# 0.3 2020-03-15

- Add basic graphic user interface 🎉 ([#19](https://github.com/tbillington/kondo/pull/19))
Expand Down
33 changes: 20 additions & 13 deletions kondo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,16 @@ pub struct ProjectSize {
}

impl Project {
pub fn artifact_dirs(&self) -> impl Iterator<Item = &str> {
pub fn artifact_dirs(&self) -> &[&str] {
match self.project_type {
ProjectType::Cargo => PROJECT_CARGO_DIRS.iter(),
ProjectType::Node => PROJECT_NODE_DIRS.iter(),
ProjectType::Unity => PROJECT_UNITY_DIRS.iter(),
ProjectType::Stack => PROJECT_STACK_DIRS.iter(),
ProjectType::SBT => PROJECT_SBT_DIRS.iter(),
ProjectType::Maven => PROJECT_MVN_DIRS.iter(),
ProjectType::Unreal => PROJECT_UNREAL_DIRS.iter(),
ProjectType::Cargo => &PROJECT_CARGO_DIRS,
ProjectType::Node => &PROJECT_NODE_DIRS,
ProjectType::Unity => &PROJECT_UNITY_DIRS,
ProjectType::Stack => &PROJECT_STACK_DIRS,
ProjectType::SBT => &PROJECT_SBT_DIRS,
ProjectType::Maven => &PROJECT_MVN_DIRS,
ProjectType::Unreal => &PROJECT_UNREAL_DIRS,
}
.copied()
}

pub fn name(&self) -> String {
Expand All @@ -86,6 +85,8 @@ impl Project {

pub fn size(&self) -> u64 {
self.artifact_dirs()
.iter()
.copied()
.map(|p| dir_size(&self.path.join(p)))
.sum()
}
Expand All @@ -106,7 +107,7 @@ impl Project {
Ok(rd) => rd,
};

let artifact_dirs: Vec<&str> = self.artifact_dirs().collect();
let artifact_dirs: Vec<&str> = self.artifact_dirs().iter().copied().collect();

for entry in project_root.filter_map(|rd| rd.ok()) {
let file_type = match entry.file_type() {
Expand Down Expand Up @@ -144,7 +145,7 @@ impl Project {
}
}

pub fn type_name(&self) -> &'static str {
pub fn type_name(&self) -> &'static str {
match self.project_type {
ProjectType::Cargo => PROJECT_CARGO_NAME,
ProjectType::Node => PROJECT_NODE_NAME,
Expand All @@ -160,6 +161,8 @@ impl Project {
pub fn clean(&self) {
for artifact_dir in self
.artifact_dirs()
.iter()
.copied()
.map(|ad| self.path.join(ad))
.filter(|ad| ad.exists())
{
Expand Down Expand Up @@ -298,6 +301,8 @@ pub fn clean(project_path: &str) -> Result<(), Box<dyn error::Error>> {
if let Some(project) = project {
for artifact_dir in project
.artifact_dirs()
.iter()
.copied()
.map(|ad| path::PathBuf::from(project_path).join(ad))
.filter(|ad| ad.exists())
{
Expand All @@ -314,6 +319,8 @@ pub fn path_canonicalise(base: &path::PathBuf, tail: path::PathBuf) -> path::Pat
if tail.is_absolute() {
tail
} else {
base.join(tail).canonicalize().expect("Unable to canonicalize!")
base.join(tail)
.canonicalize()
.expect("Unable to canonicalize!")
}
}
}
Loading

0 comments on commit 7e76b65

Please sign in to comment.