From 6d282e5ad44ab480cb961ba96ca44f3fc191f092 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sat, 16 Sep 2023 22:05:53 +0300 Subject: [PATCH] Add the action-type to distinguish the actions. --- src/cipher_analytical_machine/cli.clj | 16 ++++++++++------ src/cipher_analytical_machine/core.clj | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/cipher_analytical_machine/cli.clj b/src/cipher_analytical_machine/cli.clj index 03bb77e..d36d688 100644 --- a/src/cipher_analytical_machine/cli.clj +++ b/src/cipher_analytical_machine/cli.clj @@ -62,7 +62,12 @@ (contains? options :message-file)) (or (contains? options :encrypt) (contains? options :decrypt))) - {:options options :arguments arguments} + (cond + (contains? options :encrypt) + {:options options :arguments arguments :action-type :encrypt} + + (contains? options :decrypt) + {:options options :arguments arguments :action-type :decrypt}) :else {:exit-message (usage summary)}))) @@ -83,16 +88,15 @@ (file/read-file (:message-file options)))) (defn actions - [options arguments] - (println (str options arguments)) + [options arguments action-type] (let [message (get-message options arguments) key (Integer/parseInt (:key options)) - symbols "abc"] + symbols (:symbols options)] (println (cond - (contains? options :encrypt) + (= action-type :encrypt) (caesar/encrypt-message message key symbols) - (contains? options :decrypt) + (= action-type :decrypt) (caesar/decrypt-message message key symbols))))) diff --git a/src/cipher_analytical_machine/core.clj b/src/cipher_analytical_machine/core.clj index 3c19ef0..5e7e992 100644 --- a/src/cipher_analytical_machine/core.clj +++ b/src/cipher_analytical_machine/core.clj @@ -5,8 +5,8 @@ (defn -main [& args] - (let [{:keys [options arguments exit-message ok?]} (cli/validate-args args)] + (let [{:keys [options arguments action-type exit-message ok?]} (cli/validate-args args)] (if exit-message (cli/exit exit-message ok?) - (cli/actions options arguments)))) + (cli/actions options arguments action-type))))