<commit_before>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.

(ns containium.commands
  "Namespace for command handling."
  (:require [clojure.java.io :refer (resource as-file)]
            [clojure.pprint :refer (pprint print-table)]
            [clojure.string :refer (split trim)]
            [containium.modules :as modules]
            [containium.systems.repl :as repl]
            [containium.systems.logging :as logging :refer (refer-logging refer-command-logging)]))
(refer-logging)
(refer-command-logging)


;;; Helper functions.

(defn parse-quoted
  "Parses quoted parts in a command string. Returns [command & args]"
  [string]
  (map (fn [[normal quoted]] (or quoted normal))
       (re-seq #"'([^']+)'|[^\s]+" (trim string))))


;;; Actual commands.

(defmulti handle-command
  "This multi-method dispatches on the command argument. It also
  receives the command arguments and the systems map. The last
  argument is a CommandLogger from the logging system."
  (fn [command args systems command-logger] command))


(defmethod handle-command :default
  [command _ _ command-logger]
  (error-command command-logger "Unknown command:" command)
  (info-command command-logger "Type 'help' for info on the available commands.")
  (logging/done command-logger false))


(defmethod handle-command "help"
  [_ _ _ command-logger]
  (let [txt (str "Available commands are:"
                 "\n"
                 "\n module <list|activate|deactivate|kill|versions> [name [path]]"
                 "\n   Prints a list of installed modules, describes what is known of a module by"
                 "\n   name, activates (deploy/redeploy/swap) a module by name and path, or "
                 "\n   deactivates (undeploy) a module by name. Paths can point to a directory or"
                 "\n   to a JAR file. Killing a module is also possible, which forces the"
                 "\n   module to a halt, whatever its state. The versions actions shows the"
                 "\n   *-Version MANIFEST data in the classpath of the module."<commit_msg>Fix exception being thrown when pressing CTRL-D<commit_after>;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.

(ns containium.commands
  "Namespace for command handling."
  (:require [clojure.java.io :refer (resource as-file)]
            [clojure.pprint :refer (pprint print-table)]
            [clojure.string :refer (split trim)]
            [containium.modules :as modules]
            [containium.systems.repl :as repl]
            [containium.systems.logging :as logging :refer (refer-logging refer-command-logging)]))
(refer-logging)
(refer-command-logging)


;;; Helper functions.

(defn parse-quoted
  "Parses quoted parts in a command string. Returns [command & args]"
  [string]
  (if-not (nil? string)
    (map (fn [[normal quoted]] (or quoted normal))
         (re-seq #"'([^']+)'|[^\s]+" (trim string)))
  ;else
    ["shutdown"]))


;;; Actual commands.

(defmulti handle-command
  "This multi-method dispatches on the command argument. It also
  receives the command arguments and the systems map. The last
  argument is a CommandLogger from the logging system."
  (fn [command args systems command-logger] command))


(defmethod handle-command :default
  [command _ _ command-logger]
  (error-command command-logger "Unknown command:" command)
  (info-command command-logger "Type 'help' for info on the available commands.")
  (logging/done command-logger false))


(defmethod handle-command "help"
  [_ _ _ command-logger]
  (let [txt (str "Available commands are:"
                 "\n"
                 "\n module <list|activate|deactivate|kill|versions> [name [path]]"
                 "\n   Prints a list of installed modules, describes what is known of a module by"
                 "\n   name, activates (deploy/redeploy/swap) a module by name and path, or "
                 "\n   deactivates (undeploy) a module by name. Paths can point to a directory or"
                 "\n   to a JAR file. Killing a module is also possible, which forces the"
                 "\n   module to a halt, whatever its state. The versions actions shows the"
                 "\n   *-Version MANIFEST data in the classpath of the module."
{'fraction_non_alphanumeric': 0.10780834072759539, 'fraction_numerical': 0.001774622892635315, 'mean_word_length': 2.7954545454545454, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6617086', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1273, 'n_words': 504}