Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include project root directory in file path when rm-ing #4

Merged
merged 3 commits into from
Jun 3, 2016
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/leiningen/checkout/rm.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns leiningen.checkout.rm
(:require [fs.core :as fs]
[leiningen.checkout.utils :as utils]))
[leiningen.checkout.utils :as utils])
(:import (java.io File)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we're still importing File?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I forgot I added that. Thanks for catching it. I'll get that removed!


(defn report-no-matches [non-matched-pattern candidates]
(println (str "No matching projects found for: \""
Expand All @@ -11,21 +12,21 @@
(map println candidates))
candidates)

(defn rm-checkouts [pattern checkouts-to-rm]
(defn rm-checkouts [root pattern checkouts-to-rm]
(println (str "# `rm`ing the following projects matching \"" pattern "\":"))
(dorun
(map println checkouts-to-rm))
(dorun
(map (comp fs/delete (partial fs/file "checkouts")) checkouts-to-rm))
(map (comp fs/delete (partial fs/file root "checkouts")) checkouts-to-rm))
checkouts-to-rm)

(defn rm
"[pattern]: Remove all checkouts. If PATTERN is specified, only checkouts matching that pattern will be removed"
[{:keys [checkout] :as project} & [pattern]]
(let [current-checkouts (fs/list-dir "checkouts")
[{:keys [checkout root] :as project} & [pattern]]
(let [current-checkouts (fs/list-dir (fs/file root "checkouts"))
candidate-pattern (if pattern (re-pattern (str ".*" pattern ".*")) #".*")
candidate-matcher (partial re-matches candidate-pattern)
matching-checkouts (filter candidate-matcher current-checkouts)]
(if (= 0 (count matching-checkouts))
(report-no-matches candidate-pattern current-checkouts)
(rm-checkouts candidate-pattern matching-checkouts))))
(rm-checkouts root candidate-pattern matching-checkouts))))