module ParasitemiaUI.Args open System type Input = | File of string | Dir of string type RunningMode = | CmdLine of Input * string // A file or a directory to process and the output directory. | Window of string option // An optional path to a file to open can be given in window mode. type Arguments = RunningMode * bool // bool : true if in debug mode. let parse (args : string[]) : Arguments = let output = Array.tryFindIndex ((=) "--output") args let runningMode = match Array.tryFindIndex ((=) "--folder") args, output with | Some i, Some i_output when i < args.Length - 2 && i_output < args.Length - 2 -> CmdLine ((Dir args.[i + 1]), args.[i_output + 1]) | _ -> match Array.tryFindIndex ((=) "--file") args, output with | Some i, Some i_output when i < args.Length - 2 && i_output < args.Length - 2 -> CmdLine ((File args.[i + 1]), args.[i_output + 1]) |_ -> Window (if args.Length > 0 && not (args.[0].StartsWith ("--")) then Some args.[0] else None) runningMode, Array.exists ((=) "--debug") args let showArgsHelp () = Console.WriteLine Utils.argsHelp