<commit_before>require 'fileutils'
require 'heroku/plugin_interface'

module Heroku::Command
  class Base
    include Heroku::Helpers
    include Heroku::PluginInterface

    attr_accessor :args
    attr_reader :autodetected_app
    def initialize(args, heroku=nil)
      @args = args
      @heroku = heroku
      @autodetected_app = false
    end

    def confirm(message="Are you sure you wish to continue? (y/n)?")
      display("#{message} ", false)
      ask.downcase == 'y'
    end

    def confirm_command(app = app)
      if extract_option('--force')
        display("Warning: The --force switch is deprecated, and will be removed in a future release. Use --confirm #{app} instead.")
        return true
      end

      confirmed_app = extract_option('--confirm', false)

      raise(CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") unless app

      if confirmed_app != app
        display "\n !    Potentially Destructive Action"
        display " !    To proceed, type \"#{app}\" or re-run this command with --confirm #{@app}"
        display "> ", false
        return ask.downcase == app

        false
      else
        true
      end
    end

    def format_date(date)
      date = Time.parse(date) if date.is_a?(String)
      date.strftime("%Y-%m-%d %H:%M %Z")
    end

    def ask
      gets.strip
    end

    def shell(cmd)
      FileUtils.cd(Dir.pwd) {|d| return `#{cmd}`}
    end

    def heroku
      @heroku ||= Heroku::Command.run_internal('auth:client', args)
    end

    def extract_app(force=true)
      app = extract_option('--app', false)
      raise(CommandFailed, "You must specify an app name after --app") if app == false
      unless app
        app = extract_app_in_dir(Dir.pwd) ||
        raise(CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") if force
        @autodetected_app = true
      end
      app
    end

    def extract_app_in_dir(dir)
      return unless remotes = git_remotes(dir)

      if remote = extract_option('--remote')
        remotes[remote]
      else
        apps = remotes.values.uniq
        case apps.size
          when 0; return nil
          when 1; return apps.first
          else
            current_dir_name = dir.split('/').last.downcase
            apps.select { |a| a.downcase == current_dir_name }.first
        end
      end
    end

    def git_remotes(base_dir)
      git_config = "#{base_dir}/.git/config"
      unless File.exists?(git_config)
        parent = base_dir.split('/')[0..-2].join('/')
        return git_remotes(parent) unless parent.empty?
      else
        remotes = {}
        current_remote = nil
        File.read(git_config).split(/\n/).each do |l|
          current_remote = $1 if l.match(/\[remote \"([\w\d-]+)\"\]/)
          app = (l.match(/url = <EMAIL>}:([\w\d-]+)\.git/) || [])[1]
          if current_remote && app
            remotes[current_remote.downcase] = app
            current_remote = nil
          end
        end
        return remotes
      end
    end

    def extract_option(options, default=true)
      values = options.is_a?(Array) ? options : [options]
      return unless opt_index = args.select { |a| values.include? a }.first
      opt_position = args.index(opt_index) + 1
      if args.size > opt_position && opt_value = args[opt_position]
        if opt_value.include?('--')
          opt_value = nil
        else
          args.delete_at(opt_position)
        end
      end
      opt_value ||= default
      args.delete(opt_index)
      block_given? ? yield(opt_value) : opt_value
    end

    def web_url(name)
      "http://#{name}.#{heroku.host}/"
    end

    def git_url(name)
      "<EMAIL>}:#{name}.git"
    end

    def app_urls(name)
      "#{web_url(name)} | #{git_url(name)}"
    end

    def escape(value)
      heroku.escape(value)
    end
  end

  class BaseWithApp < Base
    attr_accessor :app

    def initialize(args, heroku=nil)
      super(args, heroku)
      @app ||= extract_app
    end
  end
end
<commit_msg>fix confirm logic to match noah's expectations<commit_after>require 'fileutils'
require 'heroku/plugin_interface'

module Heroku::Command
  class Base
    include Heroku::Helpers
    include Heroku::PluginInterface

    attr_accessor :args
    attr_reader :autodetected_app
    def initialize(args, heroku=nil)
      @args = args
      @heroku = heroku
      @autodetected_app = false
    end

    def confirm(message="Are you sure you wish to continue? (y/n)?")
      display("#{message} ", false)
      ask.downcase == 'y'
    end

    def confirm_command(app = app)
      if extract_option('--force')
        display("Warning: The --force switch is deprecated, and will be removed in a future release. Use --confirm #{app} instead.")
        return true
      end

      raise(CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") unless app

      confirmed_app = extract_option('--confirm', false)
      if confirmed_app
        unless confirmed_app == app
          raise(CommandFailed, "Confirmed app #{confirmed_app} did not match the selected app #{app}.")
        end
        return true
      else
        display "\n !    Potentially Destructive Action"
        display " !    To proceed, type \"#{app}\" or re-run this command with --confirm #{@app}"
        display "> ", false
        if ask.downcase != app
          display " !    Input did not match #{app}. Aborted."
          false
        else
          true
        end
      end
    end

    def format_date(date)
      date = Time.parse(date) if date.is_a?(String)
      date.strftime("%Y-%m-%d %H:%M %Z")
    end

    def ask
      gets.strip
    end

    def shell(cmd)
      FileUtils.cd(Dir.pwd) {|d| return `#{cmd}`}
    end

    def heroku
      @heroku ||= Heroku::Command.run_internal('auth:client', args)
    end

    def extract_app(force=true)
      app = extract_option('--app', false)
      raise(CommandFailed, "You must specify an app name after --app") if app == false
      unless app
        app = extract_app_in_dir(Dir.pwd) ||
        raise(CommandFailed, "No app specified.\nRun this command from app folder or set it adding --app <app name>") if force
        @autodetected_app = true
      end
      app
    end

    def extract_app_in_dir(dir)
      return unless remotes = git_remotes(dir)

      if remote = extract_option('--remote')
        remotes[remote]
      else
        apps = remotes.values.uniq
        case apps.size
          when 0; return nil
          when 1; return apps.first
          else
            current_dir_name = dir.split('/').last.downcase
            apps.select { |a| a.downcase == current_dir_name }.first
        end
      end
    end

    def git_remotes(base_dir)
      git_config = "#{base_dir}/.git/config"
      unless File.exists?(git_config)
        parent = base_dir.split('/')[0..-2].join('/')
        return git_remotes(parent) unless parent.empty?
      else
        remotes = {}
        current_remote = nil
        File.read(git_config).split(/\n/).each do |l|
          current_remote = $1 if l.match(/\[remote \"([\w\d-]+)\"\]/)
          app = (l.match(/url = git@#{heroku.<EMAIL>}:([\w\d-]+)\.git/) || [])[1]
          if current_remote && app
            remotes[current_remote.downcase] = app
            current_remote = nil
          end
        end
        return remotes
      end
    end

    def extract_option(options, default=true)
      values = options.is_a?(Array) ? options : [options]
      return unless opt_index = args.select { |a| values.include? a }.first
      opt_position = args.index(opt_index) + 1
      if args.size > opt_position && opt_value = args[opt_position]
        if opt_value.include?('--')
          opt_value = nil
        else
          args.delete_at(opt_position)
        end
      end
      opt_value ||= default
      args.delete(opt_index)
      block_given? ? yield(opt_value) : opt_value
    end

    def web_url(name)
      "http://#{name}.#{heroku.host}/"
    end

    def git_url(name)
      "git@#{heroku.host}:#{name}.git"
    end

    def app_urls(name)
      "#{web_url(name)} | #{git_url(name)}"
    end

    def escape(value)
      heroku.escape(value)
    end
  end

  class BaseWithApp < Base
    attr_accessor :app

    def initialize(args, heroku=nil)
      super(args, heroku)
      @app ||= extract_app
    end
  end
end

{'fraction_non_alphanumeric': 0.11768184506209343, 'fraction_numerical': 0.0016558249556475459, 'mean_word_length': 2.1575802837938762, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, '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': '1178565', 'n_tokens_mistral': 2665, 'n_tokens_neox': 2629, 'n_words': 699}