aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-04-09 12:43:36 -0500
committerGitHub <noreply@github.com>2022-04-09 12:43:36 -0500
commiteba718e11ee9c4c505f200d4376bd480f2db80be (patch)
treeb5b7f221ee10cb92e6dcae6634d5dff157be0b8c
parent63a34dc2fcf3c06a91af5b74dac47ecd2e19f9fa (diff)
parent47c70b89be1a13b321e2726e2f4b05af56c67e67 (diff)
downloadslskd-eba718e11ee9c4c505f200d4376bd480f2db80be.tar.gz
Merge pull request #412 from slskd/flags
Fix --help and --envars flags
-rw-r--r--src/slskd/Program.cs92
1 files changed, 53 insertions, 39 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 0857ef4d..bcf1df0a 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -1,4 +1,4 @@
-// <copyright file="Program.cs" company="slskd Team">
+// <copyright file="Program.cs" company="slskd Team">
// Copyright (c) slskd Team. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
@@ -468,31 +468,38 @@ namespace slskd
void Map(Type type)
{
- var defaults = Activator.CreateInstance(type);
- var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
-
- foreach (PropertyInfo property in props)
+ try
{
- var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(ArgumentAttribute));
- var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute));
- var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute));
+ var defaults = Activator.CreateInstance(type);
+ var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
- if (attribute != default)
+ foreach (PropertyInfo property in props)
{
- var shortName = (char)attribute.ConstructorArguments[0].Value;
- var longName = (string)attribute.ConstructorArguments[1].Value;
- var description = descriptionAttribute?.ConstructorArguments[0].Value;
-
- var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})";
- var item = $"{(shortName == default ? " " : $"{shortName}|")}--{GetLongName(longName, property.PropertyType)}";
- var desc = $"{description}{(property.PropertyType == typeof(bool) ? string.Empty : suffix)}";
- lines.Add(new(item, desc));
- }
- else
- {
- Map(property.PropertyType);
+ var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(ArgumentAttribute));
+ var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute));
+ var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute));
+
+ if (attribute != default)
+ {
+ var shortName = (char)attribute.ConstructorArguments[0].Value;
+ var longName = (string)attribute.ConstructorArguments[1].Value;
+ var description = descriptionAttribute?.ConstructorArguments[0].Value;
+
+ var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})";
+ var item = $"{(shortName == default ? " " : $"{shortName}|")}--{GetLongName(longName, property.PropertyType)}";
+ var desc = $"{description}{(property.PropertyType == typeof(bool) ? string.Empty : suffix)}";
+ lines.Add(new(item, desc));
+ }
+ else
+ {
+ Map(property.PropertyType);
+ }
}
}
+ catch
+ {
+ return;
+ }
}
Map(targetType);
@@ -516,30 +523,37 @@ namespace slskd
void Map(Type type)
{
- var defaults = Activator.CreateInstance(type);
- var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
-
- foreach (PropertyInfo property in props)
+ try
{
- var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(EnvironmentVariableAttribute));
- var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute));
- var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute));
+ var defaults = Activator.CreateInstance(type);
+ var props = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
- if (attribute != default)
+ foreach (PropertyInfo property in props)
{
- var name = (string)attribute.ConstructorArguments[0].Value;
- var description = descriptionAttribute?.ConstructorArguments[0].Value;
+ var attribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(EnvironmentVariableAttribute));
+ var descriptionAttribute = property.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(DescriptionAttribute));
+ var isRequired = property.CustomAttributes.Any(a => a.AttributeType == typeof(RequiredAttribute));
- var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})";
- var item = $"{prefix}{GetName(name, property.PropertyType)}";
- var desc = $"{description}{(type == typeof(bool) ? string.Empty : suffix)}";
- lines.Add(new(item, desc));
- }
- else
- {
- Map(property.PropertyType);
+ if (attribute != default)
+ {
+ var name = (string)attribute.ConstructorArguments[0].Value;
+ var description = descriptionAttribute?.ConstructorArguments[0].Value;
+
+ var suffix = isRequired ? " (required)" : $" (default: {property.GetValue(defaults) ?? "<null>"})";
+ var item = $"{prefix}{GetName(name, property.PropertyType)}";
+ var desc = $"{description}{(type == typeof(bool) ? string.Empty : suffix)}";
+ lines.Add(new(item, desc));
+ }
+ else
+ {
+ Map(property.PropertyType);
+ }
}
}
+ catch
+ {
+ return;
+ }
}
Map(targetType);