<commit_before>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#include "Support/CmdLine.h"
#include "Support/CmdLineHelp.h"
#include "Support/StringSplit.h"

#include "CmdLineQt.h"
#include "CmdLineWithIndex.h"
#include "PrettyPrint.h"

#include <functional>
#include <iostream>
#include <set>

using namespace support;

namespace support
{
namespace cl
{

    template <class T, class U>
    struct Parser<std::pair<T, U>>
    {
        bool operator ()(StringRef name, StringRef arg, size_t i, std::pair<T, U>& value) const
        {
            auto p = strings::split(arg, ":")();

            return Parser<T>()(name, p.first, i, value.first)
                && Parser<U>()(name, p.second, i, value.second);
        }
    };

    template <class T, class P>
    void prettyPrint(std::ostream& stream, Option<T, P> const& option)
    {
        stream << option.name() << ":\n";
        stream << "  count = " << option.count() << "\n";
        stream << "  value = " << pretty(option.value());
    }

    template <class T>
    void prettyPrint(std::ostream& stream, WithIndex<T> const& x)
    {
        stream << "(" << x.index << ": " << pretty(x.value) << ")";
    }

} // namespace cl
} // namespace support

struct WFlagParser
{
    bool operator ()(StringRef name, StringRef /*arg*/, size_t /*i*/, bool& value) const
    {
        value = !name.starts_with("Wno-");
        return true;
    }
};

template <class... A>
inline cl::Option<bool, WFlagParser> makeWFlag(A&&... args)
{
    return cl::makeOptionWithParser<bool>(WFlagParser(), std::forward<A>(args)..., cl::ArgDisallowed, cl::ZeroOrMore);
}

int main(int argc, char* argv[])
{
    //----------------------------------------------------------------------------------------------

    cl::CmdLine cmd;

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

    auto help = cl::makeOption<std::string>(
        cmd, "help",
        cl::ArgName("option"),
        cl::ArgOptional,
        cl::Hidden
        );

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

    double y = -1.0;

    auto y_ref = cl::makeOption<double&>(cmd, "y",
        cl::ArgName("float"),
        cl::Desc("Enter a floating-point number"),
        cl::ArgRequired,
        cl::init(y)
        );

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

    auto g  = cl::makeOption<bool>(cmd, "g", cl::Grouping, cl::ArgDisallowed, cl::ZeroOrMore);
    auto h  = cl::makeOption<bool>(cmd, "h", cl::Grouping, cl::ArgDisallowed, cl::ZeroOrMore);<commit_msg>Print errors in the test app<commit_after>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#include "Support/CmdLine.h"
#include "Support/CmdLineHelp.h"
#include "Support/StringSplit.h"

#include "CmdLineQt.h"
#include "CmdLineWithIndex.h"
#include "PrettyPrint.h"

#include <functional>
#include <iostream>
#include <set>

using namespace support;

namespace support
{
namespace cl
{

    template <class T, class U>
    struct Parser<std::pair<T, U>>
    {
        bool operator ()(StringRef name, StringRef arg, size_t i, std::pair<T, U>& value) const
        {
            auto p = strings::split(arg, ":")();

            return Parser<T>()(name, p.first, i, value.first)
                && Parser<U>()(name, p.second, i, value.second);
        }
    };

    template <class T, class P>
    void prettyPrint(std::ostream& stream, Option<T, P> const& option)
    {
        stream << option.name() << ":\n";
        stream << "  count = " << option.count() << "\n";
        stream << "  value = " << pretty(option.value());
    }

    template <class T>
    void prettyPrint(std::ostream& stream, WithIndex<T> const& x)
    {
        stream << "(" << x.index << ": " << pretty(x.value) << ")";
    }

} // namespace cl
} // namespace support

struct WFlagParser
{
    bool operator ()(StringRef name, StringRef /*arg*/, size_t /*i*/, bool& value) const
    {
        value = !name.starts_with("Wno-");
        return true;
    }
};

template <class... A>
inline cl::Option<bool, WFlagParser> makeWFlag(A&&... args)
{
    return cl::makeOptionWithParser<bool>(WFlagParser(), std::forward<A>(args)..., cl::ArgDisallowed, cl::ZeroOrMore);
}

int main(int argc, char* argv[])
{
    //----------------------------------------------------------------------------------------------

    cl::CmdLine cmd(cl::PrintErrors);

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

    auto help = cl::makeOption<std::string>(
        cmd, "help",
        cl::ArgName("option"),
        cl::ArgOptional,
        cl::Hidden
        );

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

    double y = -1.0;

    auto y_ref = cl::makeOption<double&>(cmd, "y",
        cl::ArgName("float"),
        cl::Desc("Enter a floating-point number"),
        cl::ArgRequired,
        cl::init(y)
        );

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

    auto g  = cl::makeOption<bool>(cmd, "g", cl::Grouping, cl::ArgDisallowed, cl::ZeroOrMore);
    auto h  = cl::makeOption<bool>(cmd, "h", cl::Grouping, cl::ArgDisallowed, cl::ZeroOrMore);
{'fraction_non_alphanumeric': 0.273972602739726, 'fraction_numerical': 0.0007404664938911515, 'mean_word_length': 1.70962888665998, 'pattern_counts': {'":': 6, '<': 93, '<?xml version=': 0, '>': 45, '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': '1721468', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1536, 'n_words': 370}