<commit_before>#include <iostream>
#include <cassert>
#include "HelpCmd.h"
#include "CommandSet.h"

// ---------------------------------------------------------------------------

cigma::HelpCmd::HelpCmd()
{
    name = "help";
    commands = 0;
}


cigma::HelpCmd::~HelpCmd()
{
}


void cigma::HelpCmd::setCmdMap(CommandSet::CmdMap *cmds)
{
    /* pointer to set of commands */
    this->commands = cmds;

    /* prepare usage list from current set of commands */
    usageList.clear();
    std::string prefix = "   ";
    CommandSet::CmdMap::iterator it;
    for (it = commands->begin(); it != commands->end(); ++it)
    {
        Command *cmd = it->second;
        usageList.push_back(prefix + (cmd->name));
    }
}


// ---------------------------------------------------------------------------

void cigma::HelpCmd::setupOptions(AnyOption *opt)
{
    //std::cout << "Calling cigma::HelpCmd::setupOptions()" << std::endl;

    assert(opt != 0);

    /* prepare preamble */
    opt->addUsage("Usage: cigma <subcommand> [options] [args]");
    opt->addUsage("Type 'cigma help <subcommand>' for help on a specific subcommand.");
    opt->addUsage("");
    opt->addUsage("Available subcommands");

    /* pass contents of usage list to opt object */
    std::vector<std::string>::iterator it;
    for (it = usageList.begin(); it != usageList.end(); ++it)
    {
        opt->addUsage(it->c_str());
    }

    // XXX: need to set at least one flag or option (bug in AnyOption)
    opt->setFlag("help",'h');
}


void cigma::HelpCmd::configure(AnyOption *opt)
{
    //std::cout << "Calling cigma::HelpCmd::configure()" << std::endl;

    assert(opt != 0);

    int argc = opt->getArgc();

    subcommand = "";
    if (argc == 0)
    {
        subcommand = "help";
    }
    else
    {
        subcommand = opt->getArgv(0);
        if (argc >= 2)
        {
            // XXX: too many args!
            std::cerr << "Too many arguments! "
                      << "Taking only '"
                      << subcommand
                      << "'" << std::endl;
        }
    }
}


int cigma::HelpCmd::run()
{
    //std::cout << "Calling cigma::HelpCmd::run()" << std::endl;

    CommandSet::CmdMap::iterator it = commands->find(subcommand);

    if (it != commands->end())
    {
        AnyOption opt;
        Command *cmd = it->second;<commit_msg>Added 'using namespace cigma' to HelpCmd.cpp<commit_after>#include <iostream>
#include <cassert>
#include "HelpCmd.h"
#include "CommandSet.h"

using namespace cigma;

// ---------------------------------------------------------------------------

HelpCmd::HelpCmd()
{
    name = "help";
    commands = 0;
}


HelpCmd::~HelpCmd()
{
}


void HelpCmd::setCmdMap(CommandSet::CmdMap *cmds)
{
    /* pointer to set of commands */
    this->commands = cmds;

    /* prepare usage list from current set of commands */
    usageList.clear();
    std::string prefix = "   ";
    CommandSet::CmdMap::iterator it;
    for (it = commands->begin(); it != commands->end(); ++it)
    {
        Command *cmd = it->second;
        usageList.push_back(prefix + (cmd->name));
    }
}


// ---------------------------------------------------------------------------

void HelpCmd::setupOptions(AnyOption *opt)
{
    //std::cout << "Calling cigma::HelpCmd::setupOptions()" << std::endl;

    assert(opt != 0);

    /* prepare preamble */
    opt->addUsage("Usage: cigma <subcommand> [options] [args]");
    opt->addUsage("Type 'cigma help <subcommand>' for help on a specific subcommand.");
    opt->addUsage("");
    opt->addUsage("Available subcommands");

    /* pass contents of usage list to opt object */
    std::vector<std::string>::iterator it;
    for (it = usageList.begin(); it != usageList.end(); ++it)
    {
        opt->addUsage(it->c_str());
    }

    // XXX: need to set at least one flag or option (bug in AnyOption)
    opt->setFlag("help",'h');
}


void HelpCmd::configure(AnyOption *opt)
{
    //std::cout << "Calling cigma::HelpCmd::configure()" << std::endl;

    assert(opt != 0);

    int argc = opt->getArgc();

    subcommand = "";
    if (argc == 0)
    {
        subcommand = "help";
    }
    else
    {
        subcommand = opt->getArgv(0);
        if (argc >= 2)
        {
            // XXX: too many args!
            std::cerr << "Too many arguments! "
                      << "Taking only '"
                      << subcommand
                      << "'" << std::endl;
        }
    }
}


int HelpCmd::run()
{
    //std::cout << "Calling cigma::HelpCmd::run()" << std::endl;

    CommandSet::CmdMap::iterator it = commands->find(subcommand);

    if (it != commands->end())
    {
        AnyOption opt;
        Command *cmd = it->second;
{'fraction_non_alphanumeric': 0.22908239301681924, 'fraction_numerical': 0.0025548222269533745, 'mean_word_length': 1.9866497139224413, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 49, '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': '7412545', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1405, 'n_words': 329}