diff --git a/src/cipher_analytical_machine/cli/cli.clj b/src/cipher_analytical_machine/cli/cli.clj index c0230b8..689fed4 100644 --- a/src/cipher_analytical_machine/cli/cli.clj +++ b/src/cipher_analytical_machine/cli/cli.clj @@ -5,32 +5,11 @@ [cipher-analytical-machine.analyzers.caesar :as caesar-analyzers] [cipher-analytical-machine.symbols.factories :as sf] [cipher-analytical-machine.symbols.frequencies :as symbol-frequencies] + [cipher-analytical-machine.cli.options :as options] [clojure.string :as cs] [clojure.tools.cli :refer [parse-opts]]) (:gen-class)) -(def cipher-options - #{"Caesar"}) - -(def language-options - #{"en", "uk"}) - -(def cli-options - [["-m" "--message MESSAGE" "The message will be encrypted or decrypted."] - ["-M" "--message-file MESSAGE-FILE" "The file contains the message that will be encrypted or decrypted."] - ["-k" "--key KEY" "The key will be used to encrypt or decrypt."] - ["-c" "--cipher CIPHER" "The cipher will be used to encrypt or decrypt a message." - :default "Caesar"] - ["-e" "--encrypt" "Encrypt the message."] - ["-d" "--decrypt" "Decrypt the message."] - ["-s" "--symbols" "The string will be used as a set of symbols for a cipher." - :default (sf/default-symbol-factory "en")] - ["-l" "--language CODE" "The string will be used to set a default symbols for a cipher." - :validate [#(contains? language-options %) "Must be a code from the list: en, uk!!!"]] - ["-C" "--cracking" "Cracking the encrypted message."] - ["-O" "--output-file OUTPUT-FILE" "Save the program output to a file."] - ["-h" "--help"]]) - (defn usage [options-summary] (->> ["This is cipher-analytical-machine. It can help you to learn how ciphers works." "" @@ -55,7 +34,7 @@ should exit (with an error message, and optional ok status), or a map indicating the action the program should take and the options provided." [args] - (let [{:keys [options arguments errors summary]} (parse-opts args cli-options)] + (let [{:keys [options arguments errors summary]} (parse-opts args options/cli-options)] (cond (:help options) {:exit-message (usage summary) :ok? true} diff --git a/src/cipher_analytical_machine/cli/options.clj b/src/cipher_analytical_machine/cli/options.clj new file mode 100644 index 0000000..fcf1023 --- /dev/null +++ b/src/cipher_analytical_machine/cli/options.clj @@ -0,0 +1,33 @@ +(ns cipher-analytical-machine.cli.options + (:require + [cipher-analytical-machine.symbols.factories :as sf] + [clojure.string :as cs]) + (:gen-class)) + +(def cipher-options + #{"Caesar"}) + +(def default-cipher "Caesar") + +(def language-options + #{"en", "uk"}) + +(def default-symbols + (sf/default-symbol-factory "en")) + +(def cli-options + [["-m" "--message MESSAGE" "The message will be encrypted or decrypted."] + ["-M" "--message-file MESSAGE-FILE" "The file contains the message that will be encrypted or decrypted."] + ["-k" "--key KEY" "The key will be used to encrypt or decrypt."] + ["-c" "--cipher CIPHER" "The cipher will be used to encrypt or decrypt a message." + :default default-cipher] + ["-e" "--encrypt" "Encrypt the message."] + ["-d" "--decrypt" "Decrypt the message."] + ["-s" "--symbols SYMBOLS" "The string will be used as a set of symbols for a cipher." + :default default-symbols] + ["-l" "--language CODE" "The string will be used to set a default symbols for a cipher." + :validate [#(contains? language-options %) "Must be a code from the list: en, uk!!!"]] + ["-C" "--cracking" "Cracking the encrypted message."] + ["-O" "--output-file OUTPUT-FILE" "Save the program output to a file."] + ["-h" "--help"]]) +