namespace PureGym.App open Argu open PureGym type FullnessArgsFragment = | [] Gym_Id of int | [] Gym_Name of string | [] Terse of bool interface IArgParserTemplate with member s.Usage = match s with | FullnessArgsFragment.Gym_Id _ -> "ID of the gym to look up, according to PureGym's internal mapping" | FullnessArgsFragment.Gym_Name _ -> "Name of a gym (best-guess fuzzy matching)" | FullnessArgsFragment.Terse _ -> "If true, output only the single number 'how many people are in the gym'." type FullnessArgs = { Creds : Auth Gym : GymSelector Terse : bool } static member Parse (auth : Auth) (args : FullnessArgsFragment ParseResults) : Result = let gym = match args.TryGetResult FullnessArgsFragment.Gym_Id, args.TryGetResult FullnessArgsFragment.Gym_Name with | Some _, Some _ -> failwith "--gym-id and --gym-name are mutually exclusive" | None, None -> System.Console.Error.WriteLine "No gym ID given and no gym named; assuming the user's home gym" GymSelector.Home | Some id, None -> GymSelector.Id id | None, Some name -> GymSelector.Name name { Creds = auth Gym = gym Terse = args.TryGetResult FullnessArgsFragment.Terse |> Option.defaultValue false } |> Ok [] module Fullness = let run (args : FullnessArgs) = task { let! client = Api.make args.Creds let! id = GymSelector.canonicalId client args.Gym let! attendance = client.GetGymAttendance id if args.Terse then System.Console.WriteLine attendance.TotalPeopleInGym else System.Console.WriteLine (string attendance) return 0 }