Better semantics for MemberActivity (#1)
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk> Reviewed-on: #1
This commit is contained in:
@@ -5,24 +5,45 @@ open System
|
||||
open PureGym
|
||||
|
||||
type GetTokenArg =
|
||||
| [<ExactlyOnce>] User_Email of string
|
||||
| [<ExactlyOnce>] Pin of string
|
||||
| [<Unique ; EqualsAssignmentOrSpaced>] User_Email of string
|
||||
| [<Unique ; EqualsAssignmentOrSpaced>] Pin of string
|
||||
| [<Unique>] StdIn
|
||||
|
||||
interface IArgParserTemplate with
|
||||
member s.Usage =
|
||||
match s with
|
||||
| GetTokenArg.Pin _ -> "Eight-digit PureGym user's PIN"
|
||||
| GetTokenArg.User_Email _ -> "PureGym user's email address"
|
||||
| GetTokenArg.StdIn _ -> "Read anything not specified on the command line from stdin"
|
||||
|
||||
static member Parse (args : ParseResults<GetTokenArg>) : Result<UsernamePin, ArguParseException> =
|
||||
try
|
||||
{
|
||||
Username = args.GetResult GetTokenArg.User_Email
|
||||
Pin = args.GetResult GetTokenArg.Pin
|
||||
}
|
||||
|> Ok
|
||||
with :? ArguParseException as e ->
|
||||
Error e
|
||||
let canUseStdin = args.TryGetResult(GetTokenArg.StdIn).IsSome
|
||||
|
||||
let username =
|
||||
match args.TryGetResult GetTokenArg.User_Email, canUseStdin with
|
||||
| None, true ->
|
||||
Console.Error.Write "Enter username: "
|
||||
Console.ReadLine ()
|
||||
| None, false ->
|
||||
// TODO: proper exception handling, this should be surfaced through the Error
|
||||
failwith "You must supply --user-email or --stdin"
|
||||
| Some s, _ -> s
|
||||
|
||||
let pin =
|
||||
match args.TryGetResult GetTokenArg.Pin, canUseStdin with
|
||||
| None, true ->
|
||||
Console.Error.Write "Enter eight-digit PIN: "
|
||||
Console.ReadLine ()
|
||||
| None, false ->
|
||||
// TODO: proper exception handling, this should be surfaced through the Error
|
||||
failwith "You must supply --pin or --stdin"
|
||||
| Some s, _ -> s
|
||||
|
||||
{
|
||||
Username = username
|
||||
Pin = pin
|
||||
}
|
||||
|> Ok
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Authenticate =
|
||||
|
Reference in New Issue
Block a user