Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to System.CommandLine #7653

Merged
merged 43 commits into from
Oct 31, 2024
Merged

Switch to System.CommandLine #7653

merged 43 commits into from
Oct 31, 2024

Conversation

rubo
Copy link
Contributor

@rubo rubo commented Oct 24, 2024

Replaces #4310

Changes

  • Replaced the McMaster.Extensions.CommandLineUtils with System.CommandLine as the CLI options parser
  • Changed configuration file extensions from .cfg to standard .json. The change is backward-compatible, i.e., the .cfg files are still handled if no .json equivalent is found. See Remarks below.
  • Program.cs has been heavily refactored and changed to a top-level file
  • Added new CLI option aliases to be closer to the conventional POSIX style and have less C# notation:
    nethermind --configsDirectory path/to/dir --JsonRpc.JwtSecretFile path/to/jwt.hex
    # or
    nethermind --configs-dir path/to/dir --jsonrpc-jwtsecretfile path/to/jwt.hex
  • Revised logs wording
  • Unified logging styles on startup to have coloring at the very beginning and avoid sudden formatting change on configuration load
  • Revised and improved error handling and exit codes
  • Replaced the CommandLineParser with System.CommandLine for Nethermind.Test.Runner

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

Needs manual testing

Documentation

Requires documentation update

  • Yes
  • No

PR pending.

Requires explanation in Release Notes

  • Yes
  • No

Optionally. Pending.

Remarks

The large number of changed files is due to .cfg to .json rename. I commented on the changes that need attention except for Program.cs, which has too many changes. The rest are file scope namespace changes or extension changes.

@rubo rubo force-pushed the feature/system-commandline-2 branch from 2f13e8e to 9c98998 Compare October 24, 2024 23:12
@LukaszRozmej
Copy link
Member

LukaszRozmej commented Oct 25, 2024

Can you explain why? I thought McMaster.Extensions.CommandLineUtils is quite good and solved all our issues, why System.CommandLine would be better if not only by being 1st party?

Also why change cfg to json? It was a nice distinction which is chainspec and which config.

@rubo
Copy link
Contributor Author

rubo commented Oct 25, 2024

@LukaszRozmej We had no particular issues with Microsoft.Extensions.CommandLineUtils but NuGet warnings of deprecation. The replacement McMaster.Extensions.CommandLineUtils was also abandoned by the time we picked it; its package is just not yet marked as deprecated. So, the goal here is to have something in active development and future-oriented.

.json is a well-known standard extension and is more editor-friendly and self-explanatory. Generally, I'd like to use something standard and familiar to everyone. Given we have chain specs and configs in different directories, there's no confusion, and the distinction is still clear. Moreover, chain specs are embedded in binary and are not visible to end-users.


void Load(ILogManager logManager);
void Load();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ILogManager parameter has been removed from the Load() method. Implementations can require it in their constructors if needed. This was helpful in the context of Program.cs refactoring.

namespace Nethermind.Api.Extensions
namespace Nethermind.Api.Extensions;

public class PluginLoader(string pluginPath, IFileSystem fileSystem, ILogger logger, params Type[] embedded) : IPluginLoader
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ILogger to the constructor instead of taking ILogManager in the Load() method. That's it for this file.


public void Load(ILogManager logManager) { }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed ILogManager from the Load() method. This implementation doesn't need it at all.

public CancellationToken Token => _cancellationTokenSource!.Token;
public ProcessExitSource(CancellationToken cancellationToken)
{
_cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
Copy link
Contributor Author

@rubo rubo Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.CommandLine provides a cancellation token for ctrl+c, so we don't need to handle it ourselves. Thus, ProcessExitSource now uses a linked cancellation token source to combine its own with the one of the CLI parser.


foreach (var source in _configSource)
// Skip the validation for ArgsConfigSource items as they are already validated by the CLI parser
foreach (IConfigSource source in _configSource.Where(s => s is not ArgsConfigSource))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled validation for ArgsConfigSource (CLI arguments) since the CLI parser does the job now.

@rubo rubo requested a review from LukaszRozmej October 25, 2024 17:56
@rubo rubo marked this pull request as ready for review October 26, 2024 08:40
@rubo rubo requested a review from a team as a code owner October 26, 2024 08:40
@rubo rubo force-pushed the feature/system-commandline-2 branch from 0a4d115 to 32e9120 Compare October 28, 2024 19:57
@rubo rubo requested a review from Demuirgos October 29, 2024 19:15
@rubo rubo merged commit 173a663 into master Oct 31, 2024
75 checks passed
@rubo rubo deleted the feature/system-commandline-2 branch October 31, 2024 19:31
barnabasbusa pushed a commit to ethpandaops/ethereum-package that referenced this pull request Nov 1, 2024
Fixes config file name for Nethermind:
- All *.cfg files were renamed to *.json as part of this PR:
NethermindEth/nethermind#7653
- Skipping file extension will automatically add a proper one

Signed-off-by: Alex <[email protected]>
@kamilchodola kamilchodola restored the feature/system-commandline-2 branch November 28, 2024 16:27
@rubo rubo mentioned this pull request Jan 9, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants