Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Nov 19, 2021
1 parent 01389d9 commit 15b010e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,20 @@ where the latest SHA can be found with:
$ git ls-remote https://github.com/borkdude/carve.git refs/heads/master
```

#### Clojure tool

To use as a [clojure tool](https://clojure.org/reference/deps_and_cli#tool_install):

``` shell
$ clj -Ttools install io.github.borkdude/carve '{:git/tag "v0.1.0"}' :as carve
```

## How does it work?

Carve invokes [clj-kondo](https://github.com/borkdude/clj-kondo) and uses the [analysis](https://github.com/borkdude/clj-kondo/tree/master/analysis) information to check which vars are unused. To remove the relevant bits of code it uses [rewrite-cljc](https://github.com/lread/rewrite-cljc-playground).
Carve invokes [clj-kondo](https://github.com/borkdude/clj-kondo) and uses the
[analysis](https://github.com/borkdude/clj-kondo/tree/master/analysis)
information to check which vars are unused. To remove the relevant bits of code
it uses [rewrite-cljc](https://github.com/lread/rewrite-cljc-playground).

## Usage

Expand All @@ -72,6 +83,12 @@ clojure -M:carve --opts '{:paths ["src" "test"]}'

on the JVM.

As a [clojure tool](https://clojure.org/reference/deps_and_cli#_tool_usage):

``` clojure
$ clj -Tcarve carve! '{:paths ["src"] :report {:format :text}}'
```

You can also store the config for your project in `.carve/config.edn`. When
invoking carve with no options, the options in `.carve/config.edn` will be used.
When providing options, the CLI options will take precedence over the configuration
Expand Down
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{:deps {clj-kondo/clj-kondo {:mvn/version "2021.09.26-20211013.125030-9"}
rewrite-clj/rewrite-clj {:mvn/version "1.0.572-alpha"}
expound/expound {:mvn/version "0.8.6"}}
:tools/usage {:ns-default carve.api}
:aliases {:kaocha {:extra-paths ["test"]
:extra-deps {org.clojure/test.check {:mvn/version "0.10.0"}
lambdaisland/kaocha {:mvn/version "0.0-590"}
Expand Down
2 changes: 1 addition & 1 deletion resources/CARVE_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.2
0.1.0
21 changes: 20 additions & 1 deletion src/carve/api.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns carve.api
(:refer-clojure :exclude [run!])
(:require [carve.impl :as impl]))
(:require [carve.impl :as impl]
[clojure.edn :as edn]
[clojure.java.io :as io]))

(defn print! [{:keys [:report :config]}]
(let [format (-> config :report :format)]
Expand All @@ -19,3 +21,20 @@
([] (report {:merge-config true}))
([opts]
(impl/run+ (assoc opts :report true))))

(defn carve!
"Similar as main function but with opts already parsed. Use nil opts for passing no opts.
Intended to be used with clojure -T or clojure -X."
[opts]
(let [config-file (io/file ".carve/config.edn")
config (when (.exists config-file)
(edn/read-string (slurp config-file)))]
(if (and (empty? opts) (not config))
(binding [*err* *out*]
(println "No config found in .carve/config.edn.\nSee https://github.com/borkdude/carve#usage on how to use carve.")
1)
(let [{:keys [:report :config]} (impl/run+ opts)
format (-> config :report :format)]
(when (:report config)
(impl/print-report report format))
(if (empty? report) 0 1)))))
24 changes: 6 additions & 18 deletions src/carve/main.clj
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
(ns carve.main
(:require
[carve.impl :as impl]
[clojure.edn :as edn]
[clojure.java.io :as io])
[carve.api :as api]
[clojure.edn :as edn])
(:gen-class))

(defn main
[& [flag opts & _args]]
(let [config-file (io/file ".carve/config.edn")
config (when (.exists config-file)
(edn/read-string (slurp config-file)))]
(if (and (not flag) (not config))
(binding [*err* *out*]
(println "No config found in .carve/config.edn.\nSee https://github.com/borkdude/carve#usage on how to use carve.")
1)
(do (when (and (not (= "--opts" flag)) (not config))
(throw (ex-info (str "Unrecognized option: " flag) {:flag flag})))
(let [opts (edn/read-string opts)
{:keys [:report :config]} (impl/run+ opts)
format (-> config :report :format)]
(when (:report config)
(impl/print-report report format))
(if (empty? report) 0 1))))))
(when (not (= "--opts" flag))
(throw (ex-info (str "Unrecognized option: " flag) {:flag flag})))
(let [opts (if opts (edn/read-string opts) nil)]
(api/carve! opts)))

(defn -main
[& options]
Expand Down

0 comments on commit 15b010e

Please sign in to comment.