Files
puregym-unofficial-dotnet/PureGym.App/LookupGym.fs
patrick 80e7947ae2
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Better semantics for MemberActivity (#1)
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #1
2023-10-14 17:08:17 +00:00

52 lines
1.6 KiB
Forth

namespace PureGym.App
open Argu
open PureGym
type LookupGymArgsFragment =
| [<Unique ; EqualsAssignmentOrSpaced>] Gym_Id of int
| [<Unique ; EqualsAssignmentOrSpaced>] Gym_Name of string
interface IArgParserTemplate with
member s.Usage =
match s with
| LookupGymArgsFragment.Gym_Id _ -> "ID of the gym to look up, according to PureGym's internal mapping"
| LookupGymArgsFragment.Gym_Name _ -> "Name of a gym (best-guess fuzzy matching)"
type LookupGymArgs =
{
Creds : Auth
Gym : GymSelector
}
static member Parse
(auth : Auth)
(args : LookupGymArgsFragment ParseResults)
: Result<LookupGymArgs, ArguParseException>
=
let gym =
match args.TryGetResult LookupGymArgsFragment.Gym_Id, args.TryGetResult LookupGymArgsFragment.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
}
|> Ok
[<RequireQualifiedAccess>]
module LookupGym =
let run (args : LookupGymArgs) =
task {
let! client = Api.make args.Creds
let! s = client.GetGym 19
System.Console.WriteLine (string<Gym> s)
return 0
}