<commit_before>

module Rudy
  module CLI
    class Config < Rudy::CLI::CommandBase
      
      # We force the CLI::Base#print_header to be quiet
      def print_header
        #@@global.quiet = true
        #super
      end
      
      
      # Display configuration from the local user data file (~/.rudy/config).
      # This config contains user data which is sent to each EC2 when 
      # it's created. 
      #
      # The primary purpose of this command is to give other apps a way
      # to check various configuration values. (This is mostly useful for
      # debugging and checking configuration on an instance itself).
      #
      # It will return the most specific configuration available. If the 
      # attribute isn'e found it will check each parent for the same attribute. 
      # i.e. if [prod][app][ami] is not available, it will check [prod][ami]
      # and then [ami]. 
      #
      #     # Display the value for a specific machine.
      #     $ rudy -e prod -r db config param-name
      #
      #     # Display all configuration
      #     $ rudy config --all
      #
      def config
        return if @@config.nil? 
        
        
        @option.group ||= [@@global.environment, @@global.role].join(Rudy::DELIM)
        
        return if @@config.empty?
        
        # We need to check whether we're running on a human's computer
        # or within EC2 (we call that running "in-situ"). The userdata
        # available when running in-situ is in a different format.
        if Rudy.in_situ?
          puts "TODO: do something intelligent with config when running on EC2"
        else
          if @option.all
            puts "# ACCOUNTS: not displayed"
            if @@config.machines?
              puts "# MACHINES: "
              y @@config.machines.to_hash 
            end
            if @@config.routines?
              puts "# ROUTINES: "
              y @@config.routines.to_hash 
            end
          elsif @option.defaults?
            y @@config.defaults.to_hash
          elsif @option.script
            y fetch_script_config.to_hash
          elsif @option.project
            rf = File.join(RUDY_HOME, 'Rudyfile')
            raise "Cannot find: #{rf}" unless File.exists?(rf)
            puts File.read(rf)
          else
            zon, env, rol = @@global.zone, @@global.environment, @@global.role
            usr, att = @@global.user, @argv.name
            val = @@config.machines.find_deferred(zon, env, rol, usr, att) || ''
            puts (val.is_a?(String)) ? val : val.to_hash.to_yaml
          end
          
          #name = @argv.first
          #if name && @@config.userdata.has_key?(which) 
          #  value = @@config.userdata[which][name.to_s]
          #  puts value if value
          #elsif @option.all
          #  puts @@config.to_yaml
          #else
          #  value = @@config.userdata[which] 
          #  puts value.to_yaml if value
          #end
        end
        
      end
    end
  end
end<commit_msg>Cleaned and updated config command<commit_after>

module Rudy
  module CLI
    class Config < Rudy::CLI::CommandBase
      
      # We force the CLI::Base#print_header to be quiet
      def print_header
        #@@global.quiet = true
        #super
      end
      
      
      # Display configuration from the local user data file (~/.rudy/config).
      # This config contains user data which is sent to each EC2 when 
      # it's created. 
      #
      # The primary purpose of this command is to give other apps a way
      # to check various configuration values. (This is mostly useful for
      # debugging and checking configuration on an instance itself).
      #
      # It will return the most specific configuration available. If the 
      # attribute isn'e found it will check each parent for the same attribute. 
      # i.e. if [prod][app][ami] is not available, it will check [prod][ami]
      # and then [ami]. 
      #
      #     # Display the value for a specific machine.
      #     $ rudy -e prod -r db config param-name
      #
      #     # Display all configuration
      #     $ rudy config --all
      #
      def config
        # if Rudy.in_situ? # TODO: do something intelligent when running on EC2
        
        if @@config.nil? || @@config.empty?
          return if @@global.quiet
          raise Rudy::NoConfig
        end

        outform = @@global.format == :json ? :to_json : :to_yaml
        
        types = @option.marshal_dump.keys & @@config.keys # Intersections only
        types = @@config.keys if @option.all
        types = [:machines] if types.empty?
          
        if @option.project
          rf = File.join(RUDY_HOME, 'Rudyfile')
          raise "Cannot find: #{rf}" unless File.exists?(rf)
          puts File.read(rf)
          
        elsif @option.script
          conf = fetch_script_config
          puts conf.to_hash.send(outform) if conf
        else
          puts "# ACCOUNTS: [not displayed]" if types.delete(:accounts)
          types.each do |conftype|
            puts "# #{conftype.to_s.upcase}"
            next unless @@config[conftype]  # Nothing to output
            puts @@config[conftype].to_hash.send(outform)
          end
        end
        
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08915022761760243, 'fraction_numerical': 0.0009484066767830046, 'mean_word_length': 1.7250645994832041, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7211413', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1472, 'n_words': 497}