Skip to content

Commit

Permalink
Deprecate --dependency-check-properties opt
Browse files Browse the repository at this point in the history
Don't show it in usage help.
Don't describe it in README.
Emit warning when it is used.

Closes clj-holmes#107
  • Loading branch information
lread committed Aug 19, 2024
1 parent 9ed1d5e commit 6693982
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Fix: show score and severity in dependency-check findings [#58](https://github.com/clj-holmes/clj-watson/issues/58)
* Bump deps [#75](https://github.com/clj-holmes/clj-watson/issues/75)
* Improve command line experience [#77](https://github.com/clj-holmes/clj-watson/issues/77)
* Deprecate `--dependency-check-properties` command line option [#107](https://github.com/clj-holmes/clj-watson/issues/107)
* Encourage use of NVD API key [#67](https://github.com/clj-holmes/clj-watson/issues/67)
* Explicitly close the dependency-check engine when we are done with it [#86](https://github.com/clj-holmes/clj-watson/issues/86)
* Respect dependency-check `odc.autoupdate` property [#88](https://github.com/clj-holmes/clj-watson/issues/88)
Expand Down
21 changes: 5 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ OPTIONS:
-h, --help Show usage help
OPTIONS valid when database-strategy is dependency-check:
-d, --dependency-check-properties <file> Path of a dependency-check properties file
If not provided uses resources/dependency-check.properties
-w, --clj-watson-properties <file> Path of an additional, optional properties file
Overrides values in dependency-check.properties
If not specified classpath is searched for cljwatson.properties
Expand All @@ -309,20 +307,11 @@ OPTIONS valid when database-strategy is dependency-check:
See docs for configuration. [false]
```

By default, when using the DEPENDENCY-CHECK strategy, `clj-watson` will load
its own `dependency-check.properties` file, and then look for a
`clj-watson.properties` file on the classpath and load that if found, for
additional properties to apply to the DependencyCheck scan.

If you provide `-d` (or `--dependency-check-properties`) then `clj-watson` will
load that file instead of its own `dependency-check.properties` file so it
needs to be a complete properties file, not just the properties you want to
override.

If you provide `-w` (or `--clj-watson-properties`) then `clj-watson` will load
that file and apply those properties to the dependency-check scan. This is
in addition to the properties loaded from the `dependency-check.properties`
or the `-d` file. This can be useful to override just a few properties.
When using the `dependency-check` `database-strategy`, `clj-watson` will:
- load its internal default `dependency-check.properties`
- optionally override its defaults with your `clj-watson.properties` file
- specified explicitly by you via `-w` (or `--clj-watson-properties`)
- else automatically found on your classpath

# Execution

Expand Down
31 changes: 24 additions & 7 deletions src/clj_watson/cli_spec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
(def validate-file-exists {:pred #(-> % io/file .exists)
:ex-msg (fn [_m] "Specified file not found")})

(declare styled-long-opt)

(def spec-scan-args
{:deps-edn-path
{:alias :p
Expand Down Expand Up @@ -74,7 +76,8 @@
:coerce :string
:validate validate-file-exists
:desc (str "Path of a dependency-check properties file\n"
"If not provided uses resources/dependency-check.properties")}
"If not provided uses resources/dependency-check.properties")
:deprecated-fn (fn [m] (format "Please use %s instead." (styled-long-opt :clj-watson-properties m)))}

:clj-watson-properties
{:alias :w
Expand Down Expand Up @@ -192,6 +195,21 @@
[])
(str/join "\n\n")))))

(defn- error [text]
(str "\u001B[31m* ERROR: " text "\u001B[0m"))

(defn- warning [text]
(str "\u001B[33m* WARNING: " text "\u001B[0m"))

(defn- report-deprecations [opts]
(doseq [deprecated-opt [:dependency-check-properties]]
(when (deprecated-opt opts)
(println (warning
(format "%s, %s is deprecated and will be deleted in a future release. %s"
(styled-alias (-> spec-scan-args deprecated-opt :alias) opts)
(styled-long-opt deprecated-opt opts)
((-> spec-scan-args deprecated-opt :deprecated-fn) opts)))))))

(defn- usage-help [{:keys [opts]}]
(println "clj-watson")
(println)
Expand All @@ -203,12 +221,10 @@
:groups [{:heading "OPTIONS:"
:order [:deps-edn-path :output :aliases :database-strategy :suggest-fix :fail-on-result :help]}
{:heading "OPTIONS valid when database-strategy is dependency-check:"
:order [:dependency-check-properties :clj-watson-properties :run-without-nvd-api-key]}]})))

(defn- error [text]
(str "\u001B[31m* ERROR: " text "\u001B[0m"))
:order [:clj-watson-properties :run-without-nvd-api-key]}]})))

(defn- usage-error [{:keys [spec type cause msg option opts] :as data}]
(report-deprecations opts)
(case type
:clj-watson/cli
(println (error msg))
Expand All @@ -231,7 +247,6 @@
arg-desc))))))

(throw (ex-info msg data)))
(println)
(usage-help data)
(System/exit 1))

Expand Down Expand Up @@ -261,7 +276,9 @@
:opts opts})

:else
(cli/parse-opts orig-args {:spec spec-scan-args :error-fn usage-error :restrict true}))))
(let [opts (cli/parse-opts orig-args {:spec spec-scan-args :error-fn usage-error :restrict true})]
(report-deprecations opts)
opts))))

(defn validate-tool-opts [opts]
(->> opts
Expand Down

0 comments on commit 6693982

Please sign in to comment.