-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2] make cli app work with local files
- Loading branch information
Showing
2 changed files
with
51 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,33 @@ | ||
(ns aidbox-sdk.core | ||
(:gen-class) | ||
(:require | ||
[clojure.tools.cli :as cli] | ||
[clojure.java.io :as io] | ||
[aidbox-sdk.generator :as generator])) | ||
|
||
(defn url | ||
"Safe version of as-url function" | ||
[s] | ||
(try | ||
(io/as-url s) | ||
(catch java.net.MalformedURLException _ nil) | ||
(catch java.net.URISyntaxException _ nil))) | ||
|
||
(defn resource [path] | ||
(or (url path) | ||
(io/as-file path))) | ||
|
||
(defn -main [& args] | ||
(let [[source target] (cli/parse-opts args nil)] | ||
(generator/build-all! nil))) | ||
(let [[input output] args] | ||
(cond | ||
(nil? input) | ||
(binding [*out* *err*] | ||
(println "Error: please provide an input argument")) | ||
|
||
(nil? output) | ||
(binding [*out* *err*] | ||
(println "Error: please provide an output argument")) | ||
|
||
:else | ||
(generator/build-all! | ||
(resource input) | ||
(io/as-file output))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters