<commit_before>#!/usr/bin/env ruby

require 'json'
require 'optparse'

# TODO: config option to specify command which lets check if update was executed or not (and what was updated at all)

class Updater
    CONFIG_DIR = '.upper'

    def initialize(verbose=false)
        @base_dir = File.join Dir.home, CONFIG_DIR
        @verbose = verbose
        @tasks = {}

        Dir.foreach(@base_dir) do |filename|
            path = File.join @base_dir, filename

            if File.file? path
                config = JSON.load(File.new(path))

                @tasks[filename] = {
                    :cmd => config["cmd"],
                    :hosts => config["hosts"]
                }
            end
        end
    end

    def start!
        @tasks.each do |name, config|
            if config[:hosts]
                config[:hosts].each { |host| run name, config[:cmd], host }
            else
                run name, config[:cmd]
            end
        end
    end

private
    def log(label, msg)
        puts format "[%s] %s", label, msg
    end

    def run(name, cmd, host=nil)
        label = name

        log label, "Updating"
        log label, "Command: #{cmd}" if @verbose
    
        result = (if host.nil? then `#{cmd}` else `ssh #{host} "#{cmd}"` end).strip

        log label, "ERROR while updating" unless $?.success?
        
        result = "." if result == ""

        log label, result
    end
end

<commit_msg>Prettified console output<commit_after>#!/usr/bin/env ruby

require 'json'
require 'optparse'

# TODO: config option to specify command which lets check if update was executed or not (and what was updated at all)

class Updater
    CONFIG_DIR = '.upper'

    def initialize(verbose=false)
        @base_dir = File.join Dir.home, CONFIG_DIR
        @verbose = verbose
        @tasks = {}

        Dir.foreach(@base_dir) do |filename|
            path = File.join @base_dir, filename

            if File.file? path
                config = JSON.load(File.new(path))

                @tasks[filename] = {
                    :cmd => config["cmd"],
                    :hosts => config["hosts"]
                }
            end
        end
    end

    def start!
        puts "Starting updates"

        @tasks.each do |name, config|
            if config[:hosts]
                config[:hosts].each { |host| run name, config[:cmd], host }
            else
                run name, config[:cmd]
            end
        end

        puts
        puts "Upper finished."
    end

private
    def log(msg, prefix=nil)
        prefix = " " if prefix.nil?
        puts " #{prefix} #{msg}"
    end

    def run(name, cmd, host=nil)
        label = name

        puts
        log "Updating #{name}", "-"
        log "Command: #{cmd}" if @verbose
    
        result = (if host.nil? then `#{cmd}` else `ssh #{host} "#{cmd}"` end).strip

        log "Error", "*" unless $?.success?
        
        result = "OK." if result == ""

        log result
    end
end


{'fraction_non_alphanumeric': 0.11623246492985972, 'fraction_numerical': 0.0, 'mean_word_length': 1.606614447345518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3882107', 'n_tokens_mistral': 884, 'n_tokens_neox': 842, 'n_words': 270}