62 lines
2.1 KiB
Forth
62 lines
2.1 KiB
Forth
namespace PureGym.App
|
|
|
|
open Argu
|
|
open PureGym
|
|
|
|
type FullnessArgsFragment =
|
|
| [<Unique ; EqualsAssignmentOrSpaced>] Gym_Id of int
|
|
| [<Unique ; EqualsAssignmentOrSpaced>] Gym_Name of string
|
|
| [<Unique ; EqualsAssignmentOrSpaced>] 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<FullnessArgs, ArguParseException>
|
|
=
|
|
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
|
|
|
|
[<RequireQualifiedAccess>]
|
|
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<GymAttendance> attendance)
|
|
|
|
return 0
|
|
}
|