Refactor to move options to a separated file.

dev
KKlochko 2 years ago
parent ac2cf2ac58
commit a44fc24bee

@ -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}

@ -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"]])
Loading…
Cancel
Save