<commit_before>module Ec2list
  class Command
    attr_reader :options
  
    def initialize(argv = [])
      @options = build_options(argv)
      load_profile
    end

    def run
      AWS.memoize do
        fetch_instances.each do |instance|
          print_instance(instance)
        end
      end
    end

    private

      def fetch_instances
        AWS::EC2.new.
          instances.
          select { |instance| instance.status == :running }
      end

      def print_instance(instance)
        tags = instance.tags
        puts [
          tags[:Name],
          instance.private_ip_address,
          instance.public_ip_address,
        ].join("\t")
      end

      def build_options(argv)
        Slop.parse(argv) do
          banner "Usage: ec2list [options]"

          on :p, :profile, "Profile name", argument: :optional, default: "default"
        end
      end

      def load_profile
        unless profile = AWSConfig[options[:profile]]
          raise RuntimeError, "Can't locate profile '#{options[:profile]}' in ~/.aws/config"
        end

        AWS.config(profile.config_hash)
      end
  end
end<commit_msg>Abort when specified profile not found, don't raise<commit_after>module Ec2list
  class Command
    attr_reader :options
  
    def initialize(argv = [])
      @options = build_options(argv)
      load_profile
    end

    def run
      AWS.memoize do
        fetch_instances.each do |instance|
          print_instance(instance)
        end
      end
    end

    private

      def fetch_instances
        AWS::EC2.new.
          instances.
          select { |instance| instance.status == :running }
      end

      def print_instance(instance)
        tags = instance.tags
        puts [
          tags[:Name],
          instance.private_ip_address,
          instance.public_ip_address,
        ].join("\t")
      end

      def build_options(argv)
        Slop.parse(argv) do
          banner "Usage: ec2list [options]"

          on :p, :profile, "Profile name", argument: :optional, default: "default"
        end
      end

      def load_profile
        unless profile = AWSConfig[options[:profile]]
          abort "Can't locate profile '#{options[:profile]}' in ~/.aws/config"
        end

        AWS.config(profile.config_hash)
      end
  end
end
{'fraction_non_alphanumeric': 0.08826086956521739, 'fraction_numerical': 0.0026086956521739132, 'mean_word_length': 1.8943396226415095, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2605362', 'n_tokens_mistral': 663, 'n_tokens_neox': 652, 'n_words': 165}