CLI: Allow single-character plugin option argument names

This commit is contained in:
Katy Coe
2020-12-24 01:23:16 +01:00
parent 43cef93bca
commit e7806e2849
2 changed files with 14 additions and 2 deletions

View File

@@ -90,11 +90,22 @@ namespace Il2CppInspector.CLI
} }
var pluginOptionProperty = CreateAutoProperty(pluginOptionClass, option.Name, optionType); var pluginOptionProperty = CreateAutoProperty(pluginOptionClass, option.Name, optionType);
var optCtorInfo = typeof(OptionAttribute).GetConstructor(new Type[] { typeof(string) });
ConstructorInfo optCtorInfo;
// Single character
if (option.Name.Length == 1)
optCtorInfo = typeof(OptionAttribute).GetConstructor(new Type[] { typeof(char) });
// Multiple characters
else
optCtorInfo = typeof(OptionAttribute).GetConstructor(new Type[] { typeof(string) });
var optHelpPropInfo = typeof(OptionAttribute).GetProperty("HelpText"); var optHelpPropInfo = typeof(OptionAttribute).GetProperty("HelpText");
var optDefaultInfo = typeof(OptionAttribute).GetProperty("Default"); var optDefaultInfo = typeof(OptionAttribute).GetProperty("Default");
var optRequiredInfo = typeof(OptionAttribute).GetProperty("Required"); var optRequiredInfo = typeof(OptionAttribute).GetProperty("Required");
var attBuilder = new CustomAttributeBuilder(optCtorInfo, new object[] { option.Name }, var attBuilder = new CustomAttributeBuilder(optCtorInfo,
new object[] { option.Name.Length == 1? (object) option.Name[0] : option.Name },
new PropertyInfo[] { optHelpPropInfo, optDefaultInfo, optRequiredInfo }, new PropertyInfo[] { optHelpPropInfo, optDefaultInfo, optRequiredInfo },
// Booleans are always optional // Booleans are always optional
new object[] { option.Description, optionValue, option.Value is bool? false : option.Required }); new object[] { option.Description, optionValue, option.Value is bool? false : option.Required });

View File

@@ -65,6 +65,7 @@ namespace Il2CppInspector.PluginAPI.V100
{ {
/// <summary> /// <summary>
/// The name of the option as it will be supplied in an argument on the command-line /// The name of the option as it will be supplied in an argument on the command-line
/// If you specify a single character, the single-dash syntax "-x" can be used instead of "--xxxxxx"
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; }