#include "cli/cli.h"

#include <iostream>

namespace nasal::cli {

cli_config parse(const std::vector<std::string>& args) {
    cli_config result;

    for(const auto& arg : args) {
        if (cli_options.count(arg)) {
            result.options.insert(cli_options.at(arg));
        } else if (!result.input_file_path.length()) {
            result.input_file_path = arg;
        } else {
            result.nasal_vm_args.push_back(arg);
        }
    }

    if (result.input_file_path.length() && result.options.empty()) {
        result.options.insert(option::cli_execute);
    }
    return result;
}

std::ostream& help(std::ostream& out) {
    out
    << "\n"
    << "     ,--#-,\n"
    << "<3  / \\____\\  <3\n"
    << "    |_|__A_|\n"
    << "\nnasal <option>\n"
    << "option:\n"
    << "   -h,   --help     | get help.\n"
    << "   -v,   --version  | get version.\n"
    << "   -r,   --repl     | use repl interpreter.\n"
    << "\nnasal [option] <file> [argv]\n"
    << "option:\n"
    << "   -a,   --ast      | view ast after link/optimize process.\n"
    << "         --raw-ast  | view ast without after-processing.\n"
    << "   -c,   --code     | view generated bytecode.\n"
    << "   -s,   --symbol   | show analysed symbol info.\n"
    << "   -e,   --exec     | execute directly.\n"
    << "   -t,   --time     | show execute time.\n"
    << "   -d,   --detail   | get detail info.\n"
    << "   -f,   --ref-file | get referenced files.\n"
    << "   -dbg, --debug    | debug mode.\n"
    << "         --prof     | show profiling result, "
    << "available under debug mode.\n"
    << "         --prof-all | show profiling result of all files, "
    << "available under debug mode.\n"
    << "         --limit    | use limited execution mode "
    << "(readonly api enabled).\n"
    << "file:\n"
    << "   <filename>       | execute file.\n"
    << "argv:\n"
    << "   <args>           | cmd arguments used in program.\n"
    << "\n";
    return out;
}

}