<commit_before>﻿#r "./../src/CommandLine/bin/Debug/CommandLine.dll"

open CommandLine

type options = {
    [<Option(HelpText = "Define a string value here.")>] StringValue : string;
    [<Option('i', Min = 3, Max = 4, HelpText = "Define a int sequence here.")>] IntSequence : seq<int>;
    [<Option('x', HelpText = "Define a boolean or switch value here.")>] BoolValue : bool;
    [<Value(0)>] LongValue : int64 option;
  }

let formatLong o =
  match o with
    | Some(v) -> string v
    | _ -> "{None}"

let formatInput (o : options)  =
    sprintf "--stringvalue: %s\n-i: %A\n-x: %b\nvalue: %s\n" o.StringValue (Array.ofSeq o.IntSequence) o.BoolValue (formatLong o.LongValue)

let args = fsi.CommandLineArgs.[1..]
let parsed = Parser.Default.ParseArguments<options>(args)

if Seq.isEmpty parsed.Errors
then printf "%s" (formatInput parsed.Value)
else printf "Invalid: %A\n" args<commit_msg>Active patterns<commit_after>﻿#r "./../src/CommandLine/bin/Debug/CommandLine.dll"

open CommandLine

type options = {
    [<Option(HelpText = "Define a string value here.")>] StringValue : string;
    [<Option('i', Min = 3, Max = 4, HelpText = "Define a int sequence here.")>] IntSequence : seq<int>;
    [<Option('x', HelpText = "Define a boolean or switch value here.")>] BoolValue : bool;
    [<Value(0)>] LongValue : int64 option;
  }

let formatLong o =
  match o with
    | Some(v) -> string v
    | _ -> "{None}"

let formatInput (o : options)  =
    sprintf "--stringvalue: %s\n-i: %A\n-x: %b\nvalue: %s\n" o.StringValue (Array.ofSeq o.IntSequence) o.BoolValue (formatLong o.LongValue)

let (|Parsed|Failed|) (r : ParserResult<'a>) =
  if Seq.isEmpty r.Errors then Parsed(r.Value)
  else Failed(r.Errors)

let args = fsi.CommandLineArgs.[1..]
let result = Parser.Default.ParseArguments<options>(args)

match result with
  | Parsed(opts) -> printf "%s" (formatInput opts)
  | Failed(errs) -> printf "Invalid: %A, Errors: %u\n" args (Seq.length errs)
{'fraction_non_alphanumeric': 0.1676923076923077, 'fraction_numerical': 0.006153846153846154, 'mean_word_length': 3.8054187192118225, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 22, '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': '193181', 'n_tokens_mistral': 704, 'n_tokens_neox': 688, 'n_words': 189}