Files
patrick 419f27053f
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Add all-gyms (#11)
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #11
2024-02-12 22:08:02 +00:00

54 lines
1.2 KiB
Forth

namespace PureGym.App
open System.Threading
open Argu
open PureGym
type AllGymsArgsFragment =
| [<Unique ; EqualsAssignmentOrSpaced>] Terse of bool
interface IArgParserTemplate with
member s.Usage =
match s with
| Terse _ -> "print only 'id,gym-name'"
type AllGymsArgs =
{
Creds : Auth
Terse : bool
}
static member Parse
(auth : Auth)
(args : AllGymsArgsFragment ParseResults)
: Result<AllGymsArgs, ArguParseException>
=
let terse =
match args.TryGetResult AllGymsArgsFragment.Terse with
| None -> false
| Some x -> x
{
Creds = auth
Terse = terse
}
|> Ok
[<RequireQualifiedAccess>]
module AllGyms =
let run (args : AllGymsArgs) =
task {
let! client = Api.makeWithoutRefresh CancellationToken.None args.Creds
let! s = client.GetGyms ()
if args.Terse then
for gym in s do
System.Console.WriteLine $"%i{gym.Id},%s{gym.Name}"
else
for gym in s do
System.Console.WriteLine (string<Gym> gym)
return 0
}