<commit_before>/* Simple getopt alternative. Construct a vector of options, either by using
 * reqopt, optopt, and optflag or by building them from components yourself,
 * and pass them to getopts, along with a vector of actual arguments (not
 * including argv[0]). You'll either get a failure code back, or a match.
 * You'll have to verify whether the amount of 'free' arguments in the match
 * is what you expect. Use opt_* accessors (bottom of the file) to get
 * argument values out of the match object.
 */ 

import option::some;
import option::none;

tag name { long(str); short(char); }
tag hasarg { yes; no; maybe; }
tag occur { req; optional; multi; }

type opt = rec(name name, hasarg hasarg, occur occur);

fn mkname(str nm) -> name {
    if (str::char_len(nm) == 1u) { ret short(str::char_at(nm, 0u)); }
    else { ret long(nm); }
}
fn reqopt(str name) -> opt {
    ret rec(name=mkname(name), hasarg=yes, occur=req);
}
fn optopt(str name) -> opt {
    ret rec(name=mkname(name), hasarg=yes, occur=optional);
}
fn optflag(str name) -> opt {
    ret rec(name=mkname(name), hasarg=no, occur=optional);
}<commit_msg>stdlib: Only export what's necessary from std::getopts<commit_after>/* Simple getopt alternative. Construct a vector of options, either by using
 * reqopt, optopt, and optflag or by building them from components yourself,
 * and pass them to getopts, along with a vector of actual arguments (not
 * including argv[0]). You'll either get a failure code back, or a match.
 * You'll have to verify whether the amount of 'free' arguments in the match
 * is what you expect. Use opt_* accessors (bottom of the file) to get
 * argument values out of the match object.
 */ 

import option::some;
import option::none;

export opt;

export reqopt;
export optopt;
export optflag;
export optmulti;

export getopts;

export result;
export success;
export failure;

export fail_;
export fail_str;

export opt_present;
export opt_str;
export opt_strs;
export opt_maybe_str;

tag name { long(str); short(char); }
tag hasarg { yes; no; maybe; }
tag occur { req; optional; multi; }

type opt = rec(name name, hasarg hasarg, occur occur);

fn mkname(str nm) -> name {
    if (str::char_len(nm) == 1u) { ret short(str::char_at(nm, 0u)); }
    else { ret long(nm); }
}
fn reqopt(str name) -> opt {
    ret rec(name=mkname(name), hasarg=yes, occur=req);
}
fn optopt(str name) -> opt {
    ret rec(name=mkname(name), hasarg=yes, occur=optional);
}
fn optflag(str name) -> opt {
    ret rec(name=mkname(name), hasarg=no, occur=optional);
}
{'fraction_non_alphanumeric': 0.1192443919716647, 'fraction_numerical': 0.0023612750885478157, 'mean_word_length': 4.329140461215933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5652975', 'n_tokens_mistral': 822, 'n_tokens_neox': 806, 'n_words': 324}