<commit_before># Promptml action that wraps the Trollop
# parser and responds to --help and bad
# arguments. Should be subclassed to provide
# real actions.

require 'trollop'

class TrollopAction
  def initialize &b
    @parser = Trollop::Parser.new &b
  end

  def call args
    begin
      opts = @parser.parse args
      return action opts, args
    rescue Trollop::HelpNeeded
      return help_message
    rescue Trollop::VersionNeeded
      return version_message
    rescue Trollop::CommandlineError => e
      raise "Error: #{e.message}.<br />Try --help for help."
    end
  end

  # Override this method to create your own trollop action
  # opts - the options hash as returned by trollop
  # args - remaining arguments not parsed by trollop
  def action opts, args
    <<-EOS
<pre>
Trollop diagnostics
#{help_message}
#{@parser.specs.keys.sort.collect { |k| "--#{k}=#{opts[k]}" }.join('\n') }
Remaining args: #{args.join(', ')}
</pre>
EOS
  end

  private
  def help_message
    usage = StringIO.new
    @parser.educate usage
    "<pre>#{usage.string}</pre>"
  end
  
  def version_message
    "<pre>#{@parser.version}</pre>"
  end

  def cl_error msg
    raise CommandlineError, msg
  end
end<commit_msg>Escaping pre blocks returned by TrollopAction.<commit_after># Promptml action that wraps the Trollop
# parser and responds to --help and bad
# arguments. Should be subclassed to provide
# real actions.

require 'trollop'
require 'cgi'

class TrollopAction
  def initialize &b
    @parser = Trollop::Parser.new &b
  end

  def call args
    begin
      opts = @parser.parse args
      return action opts, args
    rescue Trollop::HelpNeeded
      return pre_wrap help_message
    rescue Trollop::VersionNeeded
      return version_message
    rescue Trollop::CommandlineError => e
      raise "Error: #{e.message}.<br />Try --help for help."
    end
  end

  # Override this method to create your own trollop action
  # opts - the options hash as returned by trollop
  # args - remaining arguments not parsed by trollop
  def action opts, args
    pre_wrap <<-EOS
Trollop diagnostics
#{help_message}
#{@parser.specs.keys.sort.collect { |k| "--#{k}=#{opts[k]}" }.join("\n") }
Remaining args: #{args.join(', ')}
EOS
  end

  private
  # Format the given string by escaping any
  # sensitive html characters and wrapping
  # it in &lt;pre&gt; tags.
  def pre_wrap str
    "<pre>#{CGI.escapeHTML(str)}</pre>"
  end

  def help_message
    usage = StringIO.new
    @parser.educate usage
    usage.string
  end
  
  def version_message
    "<pre>#{@parser.version}</pre>"
  end

  def cl_error msg
    raise CommandlineError, msg
  end
end
{'fraction_non_alphanumeric': 0.10313562523611636, 'fraction_numerical': 0.0, 'mean_word_length': 3.183254344391785, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, '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': '5247730', 'n_tokens_mistral': 860, 'n_tokens_neox': 855, 'n_words': 283}