diff --git a/scripts/nethermind.service b/scripts/nethermind.service index c51eda62f2d..cafa88e9b23 100644 --- a/scripts/nethermind.service +++ b/scripts/nethermind.service @@ -11,7 +11,7 @@ User=nethermind Group=nethermind EnvironmentFile=/home/nethermind/.env WorkingDirectory=/home/nethermind -ExecStart=/home/nethermind/build/nethermind -dd /home/nethermind/data +ExecStart=/home/nethermind/build/nethermind --data-dir /home/nethermind/data Restart=on-failure LimitNOFILE=1000000 diff --git a/src/Nethermind/Nethermind.Runner/Program.cs b/src/Nethermind/Nethermind.Runner/Program.cs index f98f3503dc6..70482fc1a88 100644 --- a/src/Nethermind/Nethermind.Runner/Program.cs +++ b/src/Nethermind/Nethermind.Runner/Program.cs @@ -232,6 +232,11 @@ async Task RunAsync(ParseResult parseResult, PluginLoader pluginLoader, Can void AddConfigurationOptions(CliCommand command) { + static CliOption CreateOption(string name, Type configType) => + new CliOption( + $"--{ConfigExtensions.GetCategoryName(configType)}.{name}", + $"--{ConfigExtensions.GetCategoryName(configType)}-{name}".ToLowerInvariant()); + IEnumerable configTypes = TypeDiscovery .FindNethermindBasedTypes(typeof(IConfig)) .Where(ct => ct.IsInterface); @@ -249,27 +254,25 @@ void AddConfigurationOptions(CliCommand command) bool categoryHidden = typeLevel?.HiddenFromDocs == true; - foreach (PropertyInfo propertyInfo in + foreach (PropertyInfo prop in configType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p => p.Name)) { - ConfigItemAttribute? configItemAttribute = propertyInfo.GetCustomAttribute(); + ConfigItemAttribute? configItemAttribute = prop.GetCustomAttribute(); if (configItemAttribute?.DisabledForCli != true) { - 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", - Hidden = hidden - }); + CliOption option = prop.PropertyType == typeof(bool) + ? CreateOption(prop.Name, configType) + : CreateOption(prop.Name, configType); + option.Description = configItemAttribute?.Description; + option.HelpName = "value"; + option.Hidden = categoryHidden || configItemAttribute?.HiddenFromDocs == true; + + command.Add(option); } if (configItemAttribute?.IsPortOption == true) - ConfigExtensions.AddPortOptionName(configType, propertyInfo.Name); + ConfigExtensions.AddPortOptionName(configType, prop.Name); } } } @@ -311,9 +314,9 @@ CliConfiguration ConfigureCli() if (versionOption is not null) { - versionOption.Action = new AnonymousCliAction(r => + versionOption.Action = new AnonymousCliAction(parseResult => { - Console.WriteLine($""" + parseResult.Configuration.Output.WriteLine($""" Version: {ProductInfo.Version} Commit: {ProductInfo.Commit} Build date: {ProductInfo.BuildTimestamp:u} @@ -386,7 +389,10 @@ IConfigProvider CreateConfigProvider(ParseResult parseResult) { if (child is OptionResult result) { - var value = result.GetValueOrDefault(); + var isBoolean = result.Option.GetType().GenericTypeArguments.SingleOrDefault() == typeof(bool); + var value = isBoolean + ? result.GetValueOrDefault().ToString().ToLowerInvariant() + : result.GetValueOrDefault(); if (value is not null) configArgs.Add(result.Option.Name.TrimStart('-'), value); @@ -435,10 +441,6 @@ IConfigProvider CreateConfigProvider(ParseResult parseResult) logger.Warn($"'{name}.cfg' is deprecated. Use '{name}' instead."); } } - else - { - configFile = configFile.GetApplicationResourcePath(); - } // Resolve the full path for logging purposes configFile = Path.GetFullPath(configFile); diff --git a/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json b/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json index 5a81582f559..8332667aeae 100644 --- a/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json +++ b/src/Nethermind/Nethermind.Runner/Properties/launchSettings.json @@ -23,7 +23,7 @@ }, "Energy Web": { "commandName": "Project", - "commandLineArgs": "-c energyweb --data-dir .data --jsonrpc-enabled true", + "commandLineArgs": "-c energyweb --data-dir .data --jsonrpc-enabled", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -107,7 +107,7 @@ }, "Volta": { "commandName": "Project", - "commandLineArgs": "-c volta --data-dir .data --jsonrpc-enabled true", + "commandLineArgs": "-c volta --data-dir .data --jsonrpc-enabled", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/tools/DocGen/ConfigGenerator.cs b/tools/DocGen/ConfigGenerator.cs index aa39b045c3d..8810540e3da 100644 --- a/tools/DocGen/ConfigGenerator.cs +++ b/tools/DocGen/ConfigGenerator.cs @@ -85,6 +85,9 @@ private static void WriteMarkdown(StreamWriter file, Type configType) if (!props.Any()) return; + static (string, string) GetValue(PropertyInfo prop) => + prop.PropertyType == typeof(bool) ? ("true|false", "[true|false]") : ("", ""); + var moduleName = configType.Name[1..].Replace("Config", null); file.WriteLine($""" @@ -100,6 +103,7 @@ private static void WriteMarkdown(StreamWriter file, Type configType) continue; var description = itemAttr.Description.Replace("\n", "\n ").TrimEnd(' '); + (string value, string cliValue) = GetValue(prop); file.Write($$""" - #### `{{moduleName}}.{{prop.Name}}` \{#{{moduleName.ToLowerInvariant()}}-{{prop.Name.ToLowerInvariant()}}\} @@ -107,20 +111,20 @@ private static void WriteMarkdown(StreamWriter file, Type configType) ``` - --{{moduleName.ToLowerInvariant()}}-{{prop.Name.ToLowerInvariant()}} - --{{moduleName}}.{{prop.Name}} + --{{moduleName.ToLowerInvariant()}}-{{prop.Name.ToLowerInvariant()}} {{cliValue}} + --{{moduleName}}.{{prop.Name}} {{cliValue}} ``` ``` - NETHERMIND_{{moduleName.ToUpperInvariant()}}CONFIG_{{prop.Name.ToUpperInvariant()}}= + NETHERMIND_{{moduleName.ToUpperInvariant()}}CONFIG_{{prop.Name.ToUpperInvariant()}}={{value}} ``` ```json { "{{moduleName}}": { - "{{prop.Name}}": + "{{prop.Name}}": {{value}} } } ```