mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
CLI
This commit is contained in:
parent
5f874bc112
commit
c8c291fe61
@ -12,6 +12,10 @@
|
|||||||
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Esiur\Esiur.csproj" />
|
<ProjectReference Include="..\Esiur\Esiur.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
26
Esiur.CLI/GetTemplateOptions.cs
Normal file
26
Esiur.CLI/GetTemplateOptions.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using CommandLine;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Esiur.CLI
|
||||||
|
{
|
||||||
|
internal class GetTemplateOptions
|
||||||
|
{
|
||||||
|
[Option('d', "dir", Required = false, HelpText = "Directory name where the generated models will be saved.")]
|
||||||
|
public string Dir { get; set; }
|
||||||
|
|
||||||
|
[Option('u', "username", Required = false, HelpText = "Authentication username.")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[Option('p', "password", Required = false, HelpText = "Authentication password.")]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[Option('a', "async-setters", Required = false, HelpText = "Use asynchronous property setters.")]
|
||||||
|
public bool AsyncSetters { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,11 @@
|
|||||||
|
|
||||||
|
using CommandLine;
|
||||||
|
using Esiur.CLI;
|
||||||
using Esiur.Data;
|
using Esiur.Data;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@ -16,22 +19,18 @@ static void Main(string[] args)
|
|||||||
{
|
{
|
||||||
var url = args[1];
|
var url = args[1];
|
||||||
|
|
||||||
var parameters = GetParams(args, 2);
|
Parser.Default.ParseArguments<GetTemplateOptions>(args.Skip(2))
|
||||||
|
.WithParsed<GetTemplateOptions>(o =>
|
||||||
|
{
|
||||||
var username = args.ElementAtOrDefault(3);
|
try
|
||||||
var password = args.ElementAtOrDefault(4);
|
{
|
||||||
var asyncSetters = Convert.ToBoolean(args.ElementAtOrDefault(5));
|
var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url, o.Dir, o.Username, o.Password, o.AsyncSetters);
|
||||||
|
Console.WriteLine($"Generated successfully: {path}");
|
||||||
var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url,
|
}
|
||||||
parameters["-d"] ?? parameters["--dir"],
|
catch (Exception ex) {
|
||||||
parameters["-u"] ?? parameters["--username"],
|
Console.WriteLine(ex.ToString());
|
||||||
parameters["-p"] ?? parameters["--password"],
|
}
|
||||||
parameters["-d"] ?? parameters["--dir"]
|
});
|
||||||
parameters.Contains ["--a"] ?? parameters["--dir"]);
|
|
||||||
|
|
||||||
Console.WriteLine($"Generated successfully: {path}");
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -40,23 +39,17 @@ static void Main(string[] args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (args[0].ToLower() == "version")
|
||||||
|
{
|
||||||
|
var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion;
|
||||||
|
|
||||||
|
Console.WriteLine(version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintHelp();
|
PrintHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringKeyList GetParams(string[] args, int offset)
|
|
||||||
{
|
|
||||||
var rt = new StringKeyList();
|
|
||||||
for(var i = offset; i< args.Length; i+=2)
|
|
||||||
{
|
|
||||||
var v = args.Length >= (i + 1) ? args[i+1] : null;
|
|
||||||
rt.Add(args[i], v);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintHelp()
|
static void PrintHelp()
|
||||||
{
|
{
|
||||||
var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion;
|
var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion;
|
||||||
@ -71,6 +64,7 @@ static void PrintHelp()
|
|||||||
Console.WriteLine("Global options:");
|
Console.WriteLine("Global options:");
|
||||||
Console.WriteLine("\t-u, --username\tAuthentication username.");
|
Console.WriteLine("\t-u, --username\tAuthentication username.");
|
||||||
Console.WriteLine("\t-p, --password\tAuthentication password.");
|
Console.WriteLine("\t-p, --password\tAuthentication password.");
|
||||||
Console.WriteLine("\t-d, --dir\tName of the directory to generate model inside.");
|
Console.WriteLine("\t-d, --dir\tDirectory name where the generated models will be saved.");
|
||||||
|
Console.WriteLine("\t-a, --async-setters\tUse asynchronous property setters.");
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user