Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 363c078321 |
@@ -136,10 +136,16 @@ public static class ArgumentsParser
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToArguments<T>(T options)
|
/// <summary>
|
||||||
|
/// Формирование строки аргументов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ToArguments<T>(T options, bool useShortName = false)
|
||||||
{
|
{
|
||||||
var props = typeof(T).GetProperties();
|
var props = typeof(T).GetProperties();
|
||||||
var parts = new List<string>();
|
var parts = new List<KeyValuePair<string, string>>();
|
||||||
|
|
||||||
foreach (var prop in props)
|
foreach (var prop in props)
|
||||||
{
|
{
|
||||||
@@ -151,17 +157,22 @@ public static class ArgumentsParser
|
|||||||
|
|
||||||
string prefix = "--" + opt.Name;
|
string prefix = "--" + opt.Name;
|
||||||
|
|
||||||
|
if (useShortName && !string.IsNullOrWhiteSpace(opt.ShortName))
|
||||||
|
{
|
||||||
|
prefix = "-" + opt.ShortName;
|
||||||
|
}
|
||||||
|
|
||||||
if (prop.PropertyType == typeof(bool))
|
if (prop.PropertyType == typeof(bool))
|
||||||
{
|
{
|
||||||
if ((bool)value)
|
if ((bool)value)
|
||||||
parts.Add(prefix);
|
parts.Add(new(prefix, ""));
|
||||||
}
|
}
|
||||||
else if (prop.PropertyType.IsGenericType &&
|
else if (prop.PropertyType.IsGenericType &&
|
||||||
prop.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
|
prop.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
|
||||||
{
|
{
|
||||||
var list = (System.Collections.IList)value;
|
var list = (System.Collections.IList)value;
|
||||||
if (list.Count > 0)
|
if (list.Count > 0)
|
||||||
parts.Add($"{prefix} {string.Join(",", list.Cast<object>())}");
|
parts.Add(new(prefix, string.Join(",", list.Cast<object>())));
|
||||||
}
|
}
|
||||||
else if (prop.PropertyType.IsGenericType &&
|
else if (prop.PropertyType.IsGenericType &&
|
||||||
prop.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
|
prop.PropertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
|
||||||
@@ -171,15 +182,15 @@ public static class ArgumentsParser
|
|||||||
foreach (var k in dict.Keys)
|
foreach (var k in dict.Keys)
|
||||||
items.Add($"{k}={dict[k]}");
|
items.Add($"{k}={dict[k]}");
|
||||||
if (items.Count > 0)
|
if (items.Count > 0)
|
||||||
parts.Add($"{prefix} {string.Join(",", items)}");
|
parts.Add(new(prefix, string.Join(",", items)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parts.Add($"{prefix} {value}");
|
parts.Add(new(prefix, $"{value}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return string.Join(" ", parts);
|
return string.Join(" ", parts.Select(kvp => kvp.Key + " \"" + kvp.Value + "\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryParse(Type targetType, string input, IOptionConverter? converterAttr, out object? value)
|
private static bool TryParse(Type targetType, string input, IOptionConverter? converterAttr, out object? value)
|
||||||
|
|||||||
@@ -40,10 +40,14 @@ internal class Program
|
|||||||
Console.WriteLine($"Environment: {result.Value.Environment}");
|
Console.WriteLine($"Environment: {result.Value.Environment}");
|
||||||
Console.WriteLine($"DryRun: {result.Value.DryRun}");
|
Console.WriteLine($"DryRun: {result.Value.DryRun}");
|
||||||
Console.WriteLine($"Mode: {result.Value.Mode}");
|
Console.WriteLine($"Mode: {result.Value.Mode}");
|
||||||
|
Console.WriteLine($"Path: {result.Value.Path}");
|
||||||
Console.WriteLine($"Config.Author: {result.Value.Config.Author}");
|
Console.WriteLine($"Config.Author: {result.Value.Config.Author}");
|
||||||
Console.WriteLine($"Config.Timeout: {result.Value.Config.Timeout}");
|
Console.WriteLine($"Config.Timeout: {result.Value.Config.Timeout}");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
|
|
||||||
|
Console.WriteLine("Строка аргументов:");
|
||||||
|
Console.WriteLine(ArgumentsParser.ToArguments(result.Value!, true));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -63,6 +67,9 @@ public class DeployOptions
|
|||||||
[AllowedValues("dev", "staging", "prod")]
|
[AllowedValues("dev", "staging", "prod")]
|
||||||
public string Environment { get; set; } = "dev";
|
public string Environment { get; set; } = "dev";
|
||||||
|
|
||||||
|
[Option("path", null, "Среда деплоя")]
|
||||||
|
public string? Path { get; set; }
|
||||||
|
|
||||||
[Option("dry-run", "d", "Пробный запуск без изменений")]
|
[Option("dry-run", "d", "Пробный запуск без изменений")]
|
||||||
public bool DryRun { get; set; }
|
public bool DryRun { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"Demo": {
|
"Demo": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "--server myhost --port 8080 --env staging --mode Incremental --config \"{\\\"Author\\\":\\\"FrigaT\\\",\\\"Timeout\\\":60}"
|
"commandLineArgs": "--server \"myhost\" --port 8080 --path \"C:\\Job\\Projects\\FrigaT\\ReleaseUpdater\\Updater.Test\\bin\\Debug\\net8.0\" --env staging --mode Incremental --config \"{\\\"Author\\\":\\\"FrigaT\\\",\\\"Timeout\\\":60} "
|
||||||
},
|
},
|
||||||
"Demo (Error)": {
|
"Demo (Error)": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
|
|||||||
Reference in New Issue
Block a user