<commit_before>#include "hext/program-options.h"


namespace hext {


program_options::program_options(int argc, const char * argv[])
: desc("Options"),
  vm()
{
  namespace po = boost::program_options;

  this->desc.add_options()
    ("help", "This help message")
    ("hext-file,h", po::value<std::string>(), "Path to hext file")
    ("html-file,i", po::value<std::string>(), "Path to html file")
    ("lint,l", "Hext syntax check")
    ("print,p", "Print parsed hext")
    ("print-debug", "Print hext with match_count")
    ("keep-invalid", "Do not remove invalid matches")
    ("mt-graph,g", "Print match-tree as DOT")
  ;

  po::store(po::parse_command_line(argc, argv, this->desc), this->vm);
  po::notify(this->vm);
}

bool program_options::contains(const char * key) const
{
  return this->vm.count(key);
}

std::string program_options::get(const char * key) const
{
  return this->vm[key].as<std::string>();
}

void program_options::print(const char * program_name, std::ostream& out) const
{
  out << "Usage:\n"
      << program_name << " -h hext-file -i html-file\n";
  out << this->desc;
}

bool program_options::validate_or_print_error(std::ostream& out) const
{
  if( !this->contains("hext-file") )
  {
    out << "Error: Expecting hext-file\n";
    return false;
  }

  if( this->contains("print") || this->contains("lint") )
    return true;

  if( !this->contains("html-file") )
  {
    out << "Error: Expecting html-file\n";
    return false;
  }

  return true;
}


} // namespace hext

<commit_msg>add short option flag for options --print-debug and --keep-invalid<commit_after>#include "hext/program-options.h"


namespace hext {


program_options::program_options(int argc, const char * argv[])
: desc("Options"),
  vm()
{
  namespace po = boost::program_options;

  this->desc.add_options()
    ("help", "This help message")
    ("hext-file,h", po::value<std::string>(), "Path to hext file")
    ("html-file,i", po::value<std::string>(), "Path to html file")
    ("lint,l", "Hext syntax check")
    ("print,p", "Print parsed hext")
    ("print-debug,d", "Print hext with match_count")
    ("keep-invalid,k", "Do not remove invalid matches")
    ("mt-graph,g", "Print match-tree as DOT")
  ;

  po::store(po::parse_command_line(argc, argv, this->desc), this->vm);
  po::notify(this->vm);
}

bool program_options::contains(const char * key) const
{
  return this->vm.count(key);
}

std::string program_options::get(const char * key) const
{
  return this->vm[key].as<std::string>();
}

void program_options::print(const char * program_name, std::ostream& out) const
{
  out << "Usage:\n"
      << program_name << " -h hext-file -i html-file\n";
  out << this->desc;
}

bool program_options::validate_or_print_error(std::ostream& out) const
{
  if( !this->contains("hext-file") )
  {
    out << "Error: Expecting hext-file\n";
    return false;
  }

  if( this->contains("print") || this->contains("lint") )
    return true;

  if( !this->contains("html-file") )
  {
    out << "Error: Expecting html-file\n";
    return false;
  }

  return true;
}


} // namespace hext


{'fraction_non_alphanumeric': 0.18752020691884902, 'fraction_numerical': 0.0, 'mean_word_length': 4.014586709886548, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 31, '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': '7031430', 'n_tokens_mistral': 1093, 'n_tokens_neox': 1075, 'n_words': 246}