<commit_before>#include <unistd.h>
#include <string>
#include <iostream>
#include "coreclrutil.h"

namespace Cmdline
{
    void printHelp()
    {
        std::cerr << "PowerShell on Linux native host" << std::endl
                  << "Usage: powershell [assembly] [...]" << std::endl
                  << std::endl
                  << "What it does:" << std::endl
                  << "- the host assumes that PSL has been published to $CORE_ROOT," << std::endl
                  << "- the host will launch $CORE_ROOT/Microsoft.PowerShell.Linux.Host.dll" << std::endl
                  << "  if not given an explicit assembly" << std::endl
                  << "- all additional parameters at the end of the command line are forwarded" << std::endl
                  << "  to the Main function in the assembly" << std::endl
                  << "- the host will execute the Main function in the specified assembly" << std::endl
                  << std::endl
                  << "Example:" << std::endl
                  << "CORE_ROOT=/test/coreclr ./powershell get-process" << std::endl;
    }

    struct Args
    {
        Args() :
            argc(0),
            argv(nullptr),
            assembly()
        {
        }

        int argc;
        char** argv;
        std::string assembly;
    };

    // checks if string ends with ".exe"
    bool isExe(std::string arg)
    {
        std::size_t dot = arg.find_last_of(".");
        return dot == std::string::npos ? false : arg.substr(dot) == ".exe";
    }

    // simple extraction of assembly.exe so we can run other hosts
    void parseCmdline(int argc, char** argv, Args& args)
    {
        // index of arguments to forward (skip zeroth)
        int i = 1;
        // if we have any arguments
        if (argc > 1)
        {
            // check if the first is an assembly.exe
            const std::string arg = argv[i];
            if (isExe(arg))
            {
                args.assembly.assign(arg);
                ++i; // don't forward the first argument
            }
        }
        // forward arguments
        args.argc = argc - i;
        args.argv = &argv[i];
    }
}

int main(int argc, char** argv)
{
    Cmdline::Args args;
    Cmdline::parseCmdline(argc, argv, args);

    void* hostHandle;
    unsigned int domainId;
    int status = startCoreCLR(
        "psl_cmdline_host",
        &hostHandle,
        &domainId);

    if (!SUCCEEDED(status))
    {<commit_msg>Clean up native host CLI<commit_after>#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <iostream>
#include "coreclrutil.h"

namespace Cmdline
{
    void printHelp()
    {
        std::cerr << "PowerShell on Linux native host" << std::endl
                  << "Usage: powershell [-a assembly] [...]" << std::endl
                  << std::endl
                  << "What it does:" << std::endl
                  << "- the host assumes that PSL has been published to $CORE_ROOT," << std::endl
                  << "- the host will launch $CORE_ROOT/Microsoft.PowerShell.Linux.Host.dll" << std::endl
                  << "  if not given an explicit assembly via -a (or --assembly)" << std::endl
                  << "- all additional parameters at the end of the command line are forwarded" << std::endl
                  << "  to the Main function in the assembly" << std::endl
                  << "- the host will execute the Main function in the specified assembly" << std::endl
                  << std::endl
                  << "Example:" << std::endl
                  << "CORE_ROOT=$(pwd)/bin ./powershell get-process" << std::endl;
    }

    struct Args
    {
        Args() :
            argc(0),
            argv(nullptr),
            assembly()
        {
        }

        int argc;
        char** argv;
        std::string assembly;
    };

    // simple CLI parsing so we can run other hosts
    void parseCmdline(int argc, char** argv, Args& args)
    {
        // index of arguments to forward (skip zeroth)
        int i = 1;
        // if we have any arguments
        if (argc > 1)
        {
            std::string arg(argv[i]);

            // handle help if first argument; note that this can't be --help
            // because the managed hosts use it
            if (arg == "--native-help")
            {
                printHelp();
                exit(0);
            }

            // check if given an explicit assembly to launch
            if (argc > 2 && (arg == "-a" || arg == "--assembly"))
            {
                args.assembly.assign(std::string(argv[i+1]));
                i += 2; // don't forward the first two arguments
            }
        }
        // forward arguments
        args.argc = argc - i;
        args.argv = &argv[i];
    }
}

int main(int argc, char** argv)
{
    Cmdline::Args args;
    Cmdline::parseCmdline(argc, argv, args);

    void* hostHandle;
    unsigned int domainId;
    int status = startCoreCLR(
        "psl_cmdline_host",
        &hostHandle,
        &domainId);

    if (!SUCCEEDED(status))
    {
{'fraction_non_alphanumeric': 0.12663495838287753, 'fraction_numerical': 0.0019817677368212444, 'mean_word_length': 1.597529593412249, 'pattern_counts': {'":': 0, '<': 106, '<?xml version=': 0, '>': 13, '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': '7607609', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1390, 'n_words': 434}