<commit_before>#include <iostream>
#include <cstdlib>

#include <setjmp.h>

#include <readline/readline.h>
#include <readline/history.h>

#include "shared.hh"
#include "eval.hh"
#include "eval-inline.hh"
#include "store-api.hh"
#include "common-opts.hh"
#include "get-drvs.hh"
#include "derivations.hh"
#include "affinity.hh"

using namespace std;
using namespace nix;


string programId = "nix-repl";


struct NixRepl
{
    string curDir;
    EvalState state;

    Strings loadedFiles;

    const static int envSize = 32768;
    StaticEnv staticEnv;
    Env * env;
    int displ;
    StringSet varNames;

    StringSet completions;
    StringSet::iterator curCompletion;

    NixRepl(const Strings & searchPath);
    void mainLoop(const Strings & files);
    void completePrefix(string prefix);
    bool getLine(string & line);
    bool processLine(string line);
    void loadFile(const Path & path);
    void initEnv();
    void reloadFiles();
    void addAttrsToScope(Value & attrs);
    void addVarToScope(const Symbol & name, Value & v);
    Expr * parseString(string s);
    void evalString(string s, Value & v);

    typedef set<Value *> ValuesSeen;
    std::ostream &  printValue(std::ostream & str, Value & v, unsigned int maxDepth);
    std::ostream &  printValue(std::ostream & str, Value & v, unsigned int maxDepth, ValuesSeen & seen);
};


void printHelp()
{
    std::cout << "Usage: nix-repl [--help|--version]";
    std::cout << std::endl;
}


string removeWhitespace(string s)
{
    s = chomp(s);
    size_t n = s.find_first_not_of(" \n\r\t");
    if (n != string::npos) s = string(s, n);
    return s;
}


NixRepl::NixRepl(const Strings & searchPath)
    : state(searchPath)
    , staticEnv(false, &state.staticBaseEnv)
{
    curDir = absPath(".");

    store = openStore();
}


void NixRepl::mainLoop(const Strings & files)
{
    std::cout << "Welcome to Nix version " << NIX_VERSION << ". Type :? for help." << std::endl << std::endl;

    for (auto & i : files)
        loadedFiles.push_back(i);<commit_msg>Expand the help message printed from --help.<commit_after>#include <iostream>
#include <cstdlib>

#include <setjmp.h>

#include <readline/readline.h>
#include <readline/history.h>

#include "shared.hh"
#include "eval.hh"
#include "eval-inline.hh"
#include "store-api.hh"
#include "common-opts.hh"
#include "get-drvs.hh"
#include "derivations.hh"
#include "affinity.hh"

using namespace std;
using namespace nix;


string programId = "nix-repl";


struct NixRepl
{
    string curDir;
    EvalState state;

    Strings loadedFiles;

    const static int envSize = 32768;
    StaticEnv staticEnv;
    Env * env;
    int displ;
    StringSet varNames;

    StringSet completions;
    StringSet::iterator curCompletion;

    NixRepl(const Strings & searchPath);
    void mainLoop(const Strings & files);
    void completePrefix(string prefix);
    bool getLine(string & line);
    bool processLine(string line);
    void loadFile(const Path & path);
    void initEnv();
    void reloadFiles();
    void addAttrsToScope(Value & attrs);
    void addVarToScope(const Symbol & name, Value & v);
    Expr * parseString(string s);
    void evalString(string s, Value & v);

    typedef set<Value *> ValuesSeen;
    std::ostream &  printValue(std::ostream & str, Value & v, unsigned int maxDepth);
    std::ostream &  printValue(std::ostream & str, Value & v, unsigned int maxDepth, ValuesSeen & seen);
};


void printHelp()
{
    cout << "Usage: nix-repl [--help] [--version] [-I path] paths...\n"
         << "\n"
         << "nix-repl is a simple read-eval-print loop (REPL) for the Nix package manager.\n"
         << "\n"
         << "Options:\n"
         << "    --help\n"
         << "        Prints out a summary of the command syntax and exits.\n"
         << "\n"
         << "    --version\n"
         << "        Prints out the Nix version number on standard output and exits.\n"
         << "\n"
         << "    -I path\n"
         << "        Add a path to the Nix expression search path. This option may be given\n"
         << "        multiple times. See the NIX_PATH environment variable for information on\n"
         << "        the semantics of the Nix search path. Paths added through -I take\n"
         << "        precedence over NIX_PATH.\n"
         << "\n"
         << "    paths...\n"
         << "        A list of paths to files containing Nix expressions which nix-repl will\n"
         << "        load and add to its scope.\n"
         << "\n"
         << "        A path surrounded in < and > will be looked up in the Nix expression search\n"
         << "        path, as in the Nix language itself.\n"
         << "\n"
         << "        If an element of paths starts with http:// or https://, it is interpreted\n"
         << "        as the URL of a tarball that will be downloaded and unpacked to a temporary\n"
         << "        location. The tarball must include a single top-level directory containing\n"
         << "        at least a file named default.nix.\n"
         << flush;
}


string removeWhitespace(string s)
{
    s = chomp(s);
    size_t n = s.find_first_not_of(" \n\r\t");
    if (n != string::npos) s = string(s, n);
    return s;
}


NixRepl::NixRepl(const Strings & searchPath)
    : state(searchPath)
    , staticEnv(false, &state.staticBaseEnv)
{
    curDir = absPath(".");

    store = openStore();
}


void NixRepl::mainLoop(const Strings & files)
{
    std::cout << "Welcome to Nix version " << NIX_VERSION << ". Type :? for help." << std::endl << std::endl;

    for (auto & i : files)
        loadedFiles.push_back(i);
{'fraction_non_alphanumeric': 0.1326912787586945, 'fraction_numerical': 0.0017834849295523454, 'mean_word_length': 2.670157068062827, 'pattern_counts': {'":': 0, '<': 98, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2789086', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1793, 'n_words': 530}