52 lines
1.6 KiB
Forth
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
|
|
}
|