<commit_before>#include <iostream>
#include <string>
#include <sstream>
#include <bitcoin/client/watcher.hpp>

/**
 * Command-line interface to the wallet watcher service.
 */
class cli
{
public:
    ~cli();
    cli();

    int run();

private:
    void cmd_exit();
    void cmd_help();
    void cmd_connect(std::stringstream &args);
    void cmd_disconnect(std::stringstream &args);
    void cmd_watch(std::stringstream &args);
    void cmd_forget(std::stringstream &args);

    libwallet::watcher watcher;
    bool done_;
};

cli::~cli()
{
}

cli::cli()
  : done_(false)
{
}

int cli::run()
{
    while (!done_)
    {
        std::cout << "> " << std::flush;

        char line[1000];
        std::cin.getline(line, sizeof(line));
        std::stringstream reader(line);
        std::string command;
        reader >> command;

        if (command == "exit")              cmd_exit();
        else if (command == "help")         cmd_help();
        else if (command == "connect")      cmd_connect(reader);
        else if (command == "disconnect")   cmd_disconnect(reader);
        else if (command == "watch")        cmd_watch(reader);
        else
            std::cout << "unknown command " << command << std::endl;
    }
    return 0;
}

void cli::cmd_exit()
{
    std::cout << "waiting for thread to stop..." << std::endl;
    done_ = true;
}

void cli::cmd_help()
{
    std::cout << "commands:" << std::endl;
    std::cout << "  exit              - leave the program" << std::endl;
    std::cout << "  help              - this menu" << std::endl;
    std::cout << "  connect <server>  - connect to obelisk server" << std::endl;
    std::cout << "  disconnect        - stop talking to the obelisk server" << std::endl;
    std::cout << "  watch <address>   - watch an address" << std::endl;
}

void cli::cmd_connect(std::stringstream &args)
{
    std::string arg;
    args >> arg;
    if (!arg.size())
    {
        std::cout << "no server given" << std::endl;
        return;
    }
    std::cout << "connecting to " << arg << std::endl;

    watcher.connect(arg);
}

void cli::cmd_disconnect(std::stringstream &args)
{
    watcher.disconnect();
}

void cli::cmd_watch(std::stringstream &args)
{
    std::string arg;
    args >> arg;
    if (!arg.size())<commit_msg>Clean up wallet watcher example code<commit_after>#include <iostream>
#include <string>
#include <sstream>
#include <bitcoin/client/watcher.hpp>

/**
 * Command-line interface to the wallet watcher service.
 */
class cli
{
public:
    ~cli();
    cli();

    int run();

private:
    void cmd_exit();
    void cmd_help();
    void cmd_connect(std::stringstream& args);
    void cmd_disconnect(std::stringstream& args);
    void cmd_watch(std::stringstream& args);

    libwallet::watcher watcher;
    bool done_;
};

cli::~cli()
{
}

cli::cli()
  : done_(false)
{
}

int cli::run()
{
    while (!done_)
    {
        std::cout << "> " << std::flush;

        char line[1000];
        std::cin.getline(line, sizeof(line));
        std::stringstream reader(line);
        std::string command;
        reader >> command;

        if (command == "exit")              cmd_exit();
        else if (command == "help")         cmd_help();
        else if (command == "connect")      cmd_connect(reader);
        else if (command == "disconnect")   cmd_disconnect(reader);
        else if (command == "watch")        cmd_watch(reader);
        else
            std::cout << "unknown command " << command << std::endl;
    }
    return 0;
}

void cli::cmd_exit()
{
    std::cout << "waiting for thread to stop..." << std::endl;
    done_ = true;
}

void cli::cmd_help()
{
    std::cout << "commands:" << std::endl;
    std::cout << "  exit              - leave the program" << std::endl;
    std::cout << "  help              - this menu" << std::endl;
    std::cout << "  connect <server>  - connect to obelisk server" << std::endl;
    std::cout << "  disconnect        - stop talking to the obelisk server" << std::endl;
    std::cout << "  watch <address>   - watch an address" << std::endl;
}

void cli::cmd_connect(std::stringstream& args)
{
    std::string arg;
    args >> arg;
    if (!arg.size())
    {
        std::cout << "no server given" << std::endl;
        return;
    }
    std::cout << "connecting to " << arg << std::endl;

    watcher.connect(arg);
}

void cli::cmd_disconnect(std::stringstream& args)
{
    watcher.disconnect();
}

void cli::cmd_watch(std::stringstream& args)
{
    std::string arg;
    args >> arg;
    if (!arg.size())
{'fraction_non_alphanumeric': 0.16898916168989161, 'fraction_numerical': 0.0022119000221190004, 'mean_word_length': 2.620496397117694, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 29, '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': '3265162', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1471, 'n_words': 359}