Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Création d'un fichier config.edn
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlynux committed Apr 25, 2021
1 parent 717316d commit 000c8d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ gradle-app.setting
.lein-repl-history
.nrepl-port

run.sh
run.sh
/config.edn
6 changes: 6 additions & 0 deletions config.edn.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
:accounts
[{:pseudo "Toto"
:username "numéro de carte"
:password "mot de passe"}]
}
2 changes: 1 addition & 1 deletion example.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#! /bin/sh

java -jar dist/library-monkey.jar user1 password1 user2 password2
java -jar dist/library-monkey.jar config.edn
27 changes: 19 additions & 8 deletions src/library_monkey/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
[cognitect.anomalies :as anom]
[clojure.core.async :as a :refer [<!! <! go chan]]))

(s/def ::credentials (s/+ (s/cat :username string? :password string?)))
(s/def ::numeric-string (s/and string? #(re-matches #"\d+" %)))
(s/def ::pseudo string?)
(s/def ::password ::numeric-string)
(s/def ::username ::numeric-string)
(s/def ::account (s/keys :req-un [::username ::password]
:opt-un [::pseudo]))
(s/def ::accounts (s/coll-of ::account))
(s/def ::config (s/keys :req-un [::accounts]))

(comment
(s/explain-data ::account {:username "TOTO" :password "156"})
)

(def discard-chan (chan 10))

Expand Down Expand Up @@ -37,7 +48,7 @@

(defn print-report [report]
(println (format "Carte %s - %d document(s)"
(:username report)
(or (:pseudo report) (:username report))
(count (:borrowings report))))
(if-let [cred-error (:credentials-error report)]
(println "Erreur lors de l'authenfication : " cred-error)
Expand Down Expand Up @@ -92,15 +103,15 @@
(net/renew identity (:code-barre borrowing)))))

(defn -main
[& args]
(let [credentials (s/conform ::credentials args)]
(if (s/invalid? credentials)
[config-file & args]
(let [config (clojure.edn/read-string (slurp config-file))]
(if (not (s/valid? ::config config))
(do
(println "Erreur dans les paramètres")
(s/explain ::credentials args)
(println "Erreur dans le format du fichier `config.edn`")
(s/explain ::config config)
(flush)
(System/exit 1))
(let [reports (generate-reports amiens-library credentials)]
(let [reports (generate-reports amiens-library (:accounts config))]
(println) ;; Newline after dots.
(println (format "Total : %d document(s)" (:count reports)))
(doseq [report (:reports reports)]
Expand Down

0 comments on commit 000c8d0

Please sign in to comment.