namespace PureGym.App open Argu open PureGym type AuthArg = | [] Bearer_Token of string | [] User_Email of string | [] Pin of string | [] Others of string interface IArgParserTemplate with member s.Usage = match s with | AuthArg.Bearer_Token _ -> "A bearer token for the PureGym API" | AuthArg.User_Email _ -> "PureGym user's email address" | AuthArg.Pin _ -> "Eight-digit PureGym user's PIN" | AuthArg.Others _ -> "" static member Parse (args : ParseResults) : Result = let unmatchedArgs = args.GetResults AuthArg.Others |> List.toArray match args.TryGetResult AuthArg.User_Email, args.TryGetResult AuthArg.Pin, args.TryGetResult AuthArg.Bearer_Token with | Some email, Some pin, _ -> let auth = Auth.User { Username = email Pin = pin } Ok (auth, unmatchedArgs) | Some _email, None, _ -> failwith "Supplied --user-email but no --pin; either both or neither are required." | None, Some _pin, _ -> failwith "Supplied --pin but no --user-email; either both or neither are required." | None, None, None -> failwith "No creds given: expected at least one of `--bearer-token` or `--user-email --pin`" | None, None, Some token -> let auth = Auth.Token (AuthToken.ofBearerToken token) Ok (auth, unmatchedArgs)