refact
parent
b4048ee769
commit
3bdecc556c
@ -0,0 +1,5 @@
|
||||
{
|
||||
"build": {
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using cli.Services;
|
||||
using System.Threading.Tasks;
|
||||
using NJsonSchema;
|
||||
using System.IO;
|
||||
|
||||
namespace cli
|
||||
{
|
||||
|
||||
public class GenerateJsonSchema
|
||||
{
|
||||
public CommandLineApplication Integrates(CommandLineApplication rootApp)
|
||||
{
|
||||
CommandArgument genargclass = null;
|
||||
CommandArgument genargjson = null;
|
||||
CommandOption genopthelp = null;
|
||||
var cmd = rootApp.Command("gen",
|
||||
(target) =>
|
||||
{
|
||||
target.FullName = "Generete";
|
||||
target.Description = "generates some objects ...";
|
||||
genopthelp = target.HelpOption("-? | -h | --help");
|
||||
genargclass = target.Argument(
|
||||
"class",
|
||||
"class name of generation to execute (actually, only 'jsonSchema') .",
|
||||
multipleValues: false);
|
||||
genargjson = target.Argument(
|
||||
"json",
|
||||
"Json file to generate a schema for.",
|
||||
multipleValues: false);
|
||||
}, false);
|
||||
cmd.OnExecute(
|
||||
async () => {
|
||||
if (genargjson.Value == "jsonSchema") {
|
||||
if (genargjson.Value == null)
|
||||
await GenerateCiBuildSettingsSchema();
|
||||
else
|
||||
await GenerateCiBuildSettingsSchema(genargjson.Value);
|
||||
} else {
|
||||
cmd.ShowHint();
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
return cmd;
|
||||
}
|
||||
public static async Task GenerateCiBuildSettingsSchema(string outputFileName = "pauls-ci-schema.json")
|
||||
{
|
||||
var schema = await JsonSchema4.FromTypeAsync<CiBuildSettings>();
|
||||
var schemaData = schema.ToJson();
|
||||
|
||||
FileInfo ofi = new FileInfo(outputFileName);
|
||||
var ostream = ofi.OpenWrite();
|
||||
var owritter = new StreamWriter(ostream);
|
||||
owritter.WriteLine(schemaData);
|
||||
owritter.Close();
|
||||
ostream.Close();
|
||||
/* var errors = schema.Validate("{...}");
|
||||
|
||||
foreach (var error in errors)
|
||||
Console.WriteLine(error.Path + ": " + error.Kind);
|
||||
|
||||
schema = await JsonSchema4.FromJsonAsync(schemaData); */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
public interface ICliTAsk
|
||||
{
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
|
||||
}
|
||||
public interface ICliCommand
|
||||
{
|
||||
CommandLineApplication Integrates(CommandLineApplication rootApp);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue