Files
puregym-unofficial-dotnet/PureGym.App/AllGyms.fs
Smaug123 43c87c7955
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/pr/all-checks-complete unknown status
Add all-gyms
2024-02-12 21:52:11 +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
}