mirror of
https://github.com/Smaug123/gitea-repo-config
synced 2025-10-11 18:28:42 +00:00
Subcommands (#62)
This commit is contained in:
47
Gitea.Declarative/OutputSchema.fs
Normal file
47
Gitea.Declarative/OutputSchema.fs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace Gitea.Declarative
|
||||
|
||||
open System.IO
|
||||
open Argu
|
||||
|
||||
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) : Async<int> =
|
||||
async {
|
||||
use stream = GiteaConfig.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
|
||||
}
|
Reference in New Issue
Block a user