From 29ba1cf123a8fb8db86f33eff350ca6c1a8ec709 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Fri, 1 Nov 2024 09:12:59 +0800 Subject: [PATCH 1/2] Fix hidden cli option not detected --- src/Nethermind/Nethermind.Runner/Program.cs | 33 ++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Nethermind/Nethermind.Runner/Program.cs b/src/Nethermind/Nethermind.Runner/Program.cs index ffc60b4971d..1a983bd7e4b 100644 --- a/src/Nethermind/Nethermind.Runner/Program.cs +++ b/src/Nethermind/Nethermind.Runner/Program.cs @@ -242,22 +242,27 @@ void AddConfigurationOptions(CliCommand command) ConfigCategoryAttribute? typeLevel = configType.GetCustomAttribute(); - if (typeLevel is not null && (typeLevel.DisabledForCli || typeLevel.HiddenFromDocs)) + if (typeLevel is not null && typeLevel.DisabledForCli) continue; + bool categoryHidden = typeLevel?.HiddenFromDocs == true; + foreach (PropertyInfo propertyInfo in - configType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name)) + configType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name)) { ConfigItemAttribute? configItemAttribute = propertyInfo.GetCustomAttribute(); - if (configItemAttribute?.DisabledForCli == false || configItemAttribute?.HiddenFromDocs == false) + if (configItemAttribute == null || configItemAttribute?.DisabledForCli == false) { + bool hidden = categoryHidden || configItemAttribute?.HiddenFromDocs == true; + command.Add(new CliOption( $"--{ConfigExtensions.GetCategoryName(configType)}.{propertyInfo.Name}", $"--{ConfigExtensions.GetCategoryName(configType)}-{propertyInfo.Name}".ToLowerInvariant()) { Description = configItemAttribute?.Description, - HelpName = "value" + HelpName = "value", + Hidden = hidden }); } @@ -287,12 +292,12 @@ CliConfiguration ConfigureCli() versionOption.Action = new AnonymousCliAction(r => { Console.WriteLine($""" - Version: {ProductInfo.Version} - Commit: {ProductInfo.Commit} - Build date: {ProductInfo.BuildTimestamp:u} - Runtime: {ProductInfo.Runtime} - Platform: {ProductInfo.OS} {ProductInfo.OSArchitecture} - """); + Version: {ProductInfo.Version} + Commit: {ProductInfo.Commit} + Build date: {ProductInfo.BuildTimestamp:u} + Runtime: {ProductInfo.Runtime} + Platform: {ProductInfo.OS} {ProductInfo.OSArchitecture} + """); return ExitCodes.Ok; }); @@ -309,7 +314,7 @@ void ConfigureLogger(ParseResult parseResult) { string nLogConfig = Path.GetFullPath( parseResult.GetValue(BasicOptions.LoggerConfigurationSource) - ?? "NLog.config".GetApplicationResourcePath()); + ?? "NLog.config".GetApplicationResourcePath()); try { @@ -371,14 +376,14 @@ IConfigProvider CreateConfigProvider(ParseResult parseResult) configProvider.AddSource(new EnvConfigSource()); string configFile = parseResult.GetValue(BasicOptions.Configuration) - ?? Environment.GetEnvironmentVariable("NETHERMIND_CONFIG") - ?? "mainnet"; + ?? Environment.GetEnvironmentVariable("NETHERMIND_CONFIG") + ?? "mainnet"; // If configFile is not a path, handle it if (string.IsNullOrEmpty(Path.GetDirectoryName(configFile))) { string configsDir = parseResult.GetValue(BasicOptions.ConfigurationDirectory) - ?? "configs".GetApplicationResourcePath(); + ?? "configs".GetApplicationResourcePath(); configFile = Path.Join(configsDir, configFile); From 6ff8efaeb78851d40a387de46439ff9cf3ba5559 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Fri, 1 Nov 2024 09:16:39 +0800 Subject: [PATCH 2/2] Reduce change --- src/Nethermind/Nethermind.Runner/Program.cs | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Nethermind/Nethermind.Runner/Program.cs b/src/Nethermind/Nethermind.Runner/Program.cs index 1a983bd7e4b..f82845be458 100644 --- a/src/Nethermind/Nethermind.Runner/Program.cs +++ b/src/Nethermind/Nethermind.Runner/Program.cs @@ -248,11 +248,11 @@ void AddConfigurationOptions(CliCommand command) bool categoryHidden = typeLevel?.HiddenFromDocs == true; foreach (PropertyInfo propertyInfo in - configType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name)) + configType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name)) { ConfigItemAttribute? configItemAttribute = propertyInfo.GetCustomAttribute(); - if (configItemAttribute == null || configItemAttribute?.DisabledForCli == false) + if (configItemAttribute?.DisabledForCli != true) { bool hidden = categoryHidden || configItemAttribute?.HiddenFromDocs == true; @@ -292,12 +292,12 @@ CliConfiguration ConfigureCli() versionOption.Action = new AnonymousCliAction(r => { Console.WriteLine($""" - Version: {ProductInfo.Version} - Commit: {ProductInfo.Commit} - Build date: {ProductInfo.BuildTimestamp:u} - Runtime: {ProductInfo.Runtime} - Platform: {ProductInfo.OS} {ProductInfo.OSArchitecture} - """); + Version: {ProductInfo.Version} + Commit: {ProductInfo.Commit} + Build date: {ProductInfo.BuildTimestamp:u} + Runtime: {ProductInfo.Runtime} + Platform: {ProductInfo.OS} {ProductInfo.OSArchitecture} + """); return ExitCodes.Ok; }); @@ -314,7 +314,7 @@ void ConfigureLogger(ParseResult parseResult) { string nLogConfig = Path.GetFullPath( parseResult.GetValue(BasicOptions.LoggerConfigurationSource) - ?? "NLog.config".GetApplicationResourcePath()); + ?? "NLog.config".GetApplicationResourcePath()); try { @@ -376,14 +376,14 @@ IConfigProvider CreateConfigProvider(ParseResult parseResult) configProvider.AddSource(new EnvConfigSource()); string configFile = parseResult.GetValue(BasicOptions.Configuration) - ?? Environment.GetEnvironmentVariable("NETHERMIND_CONFIG") - ?? "mainnet"; + ?? Environment.GetEnvironmentVariable("NETHERMIND_CONFIG") + ?? "mainnet"; // If configFile is not a path, handle it if (string.IsNullOrEmpty(Path.GetDirectoryName(configFile))) { string configsDir = parseResult.GetValue(BasicOptions.ConfigurationDirectory) - ?? "configs".GetApplicationResourcePath(); + ?? "configs".GetApplicationResourcePath(); configFile = Path.Join(configsDir, configFile);