Files
anki-static/AnkiStatic/OutputSchema.fs
patrick 4070001e55
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Add app (#4)
Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #4
2023-09-08 23:31:01 +00:00

50 lines
1.3 KiB
Forth

namespace AnkiStatic.App
open System.IO
open System.Threading.Tasks
open Argu
open AnkiStatic
type OutputSchemaArgsFragment =
| Output of string
interface IArgParserTemplate with
member s.Usage =
match s with
| Output _ -> "path to the file to be written (or overwritten, if it already exists), instead of stdout"
type OutputSchemaArgs =
{
Output : FileInfo option
}
static member OfParse
(parsed : ParseResults<OutputSchemaArgsFragment>)
: Result<OutputSchemaArgs, ArguParseException>
=
try
{
Output = parsed.TryGetResult OutputSchemaArgsFragment.Output |> Option.map FileInfo
}
|> Ok
with :? ArguParseException as e ->
Error e
[<RequireQualifiedAccess>]
module OutputSchema =
let run (args : OutputSchemaArgs) : Task<int> =
task {
use stream = AnkiStatic.getSchema ()
match args.Output with
| None ->
let reader = new StreamReader (stream)
System.Console.WriteLine (reader.ReadToEnd ())
| Some output ->
use output = output.OpenWrite ()
stream.CopyTo output
return 0
}