<commit_before>(ns matross.tasks.command
  (:require [matross.docs :refer [defdocs]]
            [matross.tasks.core :refer [deftask task-result]]
            [matross.connections.core :refer [run exit-ok?]]))

(comment
:command shell command to run
:shell system shell to use (optional)
:env map of environment (optional))

(defn key=val [map-entry]
  (let [[key val] map-entry
        keyname (name key)]
    (str keyname "=" val)))

(deftask :command [conn {:keys [shell command env]
                         :or   {shell "/bin/sh"}}]
  (let [cmd (concat ["/usr/bin/env" "-i"] (map key=val env) [shell "-c" command])
        proc (run conn {:cmd cmd})]
    (task-result (exit-ok? proc) true proc)))

(defdocs :command
  {:description "Run a shell command on a remote machine."
   :url "https://github.com/matross/matross/blob/master/plugins/matross/tasks/command.clj" 
   :options
     {:command "command to run"
      :env "map containing shell environment (optional)"
      :shell "path to shell to use (optional)"}
   :defaults {:shell "/bin/sh" :env {}}
   :examples [{:command "echo $message"
               :env {:message "hello, world!"}}]})<commit_msg>a little task cleanup :bath:<commit_after>(ns matross.tasks.command
  (:require [matross.docs :refer [defdocs]]
            [matross.tasks.core :refer [deftask task-result]]
            [matross.connections.core :refer [run exit-ok?]]))

(defn key=val [map-entry]
  (let [[key val] map-entry
        keyname (name key)]
    (str keyname "=" val)))

(defdocs :command
  {:description "Run a shell command on a remote machine."
   :url "https://github.com/matross/matross/blob/master/plugins/matross/tasks/command.clj" 
   :options {:command "command to run"
             :env "map containing shell environment (optional)"
             :shell "path to shell to use (optional)"}
   :defaults {:shell "/bin/sh" :env {}}
   :examples [{:command "echo $message"
               :env {:message "hello, world!"}}]})

(deftask :command [conn {:keys [shell command env]
                         :or   {shell "/bin/sh"}}]
  (let [cmd (concat ["/usr/bin/env" "-i"] (map key=val env) [shell "-c" command])
        proc (run conn {:cmd cmd})]
    (task-result (exit-ok? proc) true proc)))
{'fraction_non_alphanumeric': 0.1614490161001789, 'fraction_numerical': 0.0, 'mean_word_length': 2.938380281690141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2116318', 'n_tokens_mistral': 728, 'n_tokens_neox': 718, 'n_words': 222}