-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add: enable command line command #3040
Merged
Merged
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f93ce8f
enable command line command
Jim8y 86137ae
fix GUI
Jim8y 12ef4fc
Merge branch 'master' into commandline
cschuchardt88 07b246a
Merge branch 'master' into commandline
Jim8y cef330e
update format
Jim8y 78d584e
Merge branch 'master' into commandline
Jim8y 502b154
remove network config
Jim8y baa17a1
Merge branch 'master' into commandline
shargon a90b401
Fix conflicts
shargon 9b06a1b
Remove Settings messages
shargon af5dc0e
My review
shargon b0f9a22
Add NoVerify check in IsValid
shargon 392ba58
Clean using
shargon b558c50
Merge branch 'master' into commandline
Jim8y f6471cf
format
Jim8y 7d54c5d
move config
Jim8y a4c760d
Revert "move config"
Jim8y 3909261
fix config
Jim8y b530d50
update plugins install command
Jim8y d2333e9
format
Jim8y e9fc4d8
Merge branch 'master' into commandline
vncoelho c253012
fix build error
Jim8y 6f6afd1
Merge branch 'master' into commandline
vncoelho 6a7c7e6
Merge branch 'master' into commandline
vncoelho ec924a2
Update src/Neo.CLI/CLI/MainService.cs
Jim8y 1f3f7d6
Fix Contracts
shargon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// CommandLineOption.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
namespace Neo.CLI | ||
{ | ||
public class CommandLineOptions | ||
{ | ||
public string? Config { get; init; } | ||
public string? Wallet { get; init; } | ||
public string? Password { get; init; } | ||
public string[]? Plugins { get; set; } | ||
public string? DBEngine { get; init; } | ||
public string? DBPath { get; init; } | ||
public bool? NoVerify { get; init; } | ||
|
||
/// <summary> | ||
/// Check if CommandLineOptions was configured | ||
/// </summary> | ||
public bool IsValid => | ||
!string.IsNullOrEmpty(Config) || | ||
!string.IsNullOrEmpty(Wallet) || | ||
!string.IsNullOrEmpty(Password) || | ||
!string.IsNullOrEmpty(DBEngine) || | ||
!string.IsNullOrEmpty(DBPath) || | ||
(Plugins?.Length > 0) || | ||
NoVerify is not null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// MainService.CommandLine.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.CommandLine.NamingConventionBinder; | ||
using System.Reflection; | ||
|
||
namespace Neo.CLI | ||
{ | ||
public partial class MainService | ||
{ | ||
public int OnStartWithCommandLine(string[] args) | ||
{ | ||
RootCommand rootCommand = new(Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>()!.Title) | ||
{ | ||
new Option<string>(new[] { "-c", "--config","/config" }, "Specifies the config file."), | ||
new Option<string>(new[] { "-w", "--wallet","/wallet" }, "The path of the neo3 wallet [*.json]."), | ||
new Option<string>(new[] { "-p", "--password" ,"/password" }, "Password to decrypt the wallet, either from the command line or config file."), | ||
new Option<string>(new[] { "--db-engine","/db-engine" }, "Specify the db engine."), | ||
new Option<string>(new[] { "--db-path","/db-path" }, "Specify the db path."), | ||
new Option<string>(new[] { "--noverify","/noverify" }, "Indicates whether the blocks need to be verified when importing."), | ||
new Option<string[]>(new[] { "--plugins","/plugins" }, "The list of plugins, if not present, will be installed [plugin1 plugin2]."), | ||
}; | ||
|
||
rootCommand.Handler = CommandHandler.Create<RootCommand, CommandLineOptions, InvocationContext>(Handle); | ||
return rootCommand.Invoke(args); | ||
} | ||
|
||
private void Handle(RootCommand command, CommandLineOptions options, InvocationContext context) | ||
{ | ||
Start(options); | ||
} | ||
|
||
private static void CustomProtocolSettings(CommandLineOptions options, ProtocolSettings settings) | ||
{ | ||
var tempSetting = settings; | ||
// if specified config, then load the config and check the network | ||
if (!string.IsNullOrEmpty(options.Config)) | ||
{ | ||
tempSetting = ProtocolSettings.Load(options.Config); | ||
} | ||
|
||
var customSetting = new ProtocolSettings | ||
{ | ||
Network = tempSetting.Network, | ||
AddressVersion = tempSetting.AddressVersion, | ||
StandbyCommittee = tempSetting.StandbyCommittee, | ||
ValidatorsCount = tempSetting.ValidatorsCount, | ||
SeedList = tempSetting.SeedList, | ||
MillisecondsPerBlock = tempSetting.MillisecondsPerBlock, | ||
MaxTransactionsPerBlock = tempSetting.MaxTransactionsPerBlock, | ||
MemoryPoolMaxTransactions = tempSetting.MemoryPoolMaxTransactions, | ||
MaxTraceableBlocks = tempSetting.MaxTraceableBlocks, | ||
InitialGasDistribution = tempSetting.InitialGasDistribution, | ||
Hardforks = tempSetting.Hardforks | ||
}; | ||
|
||
if (!string.IsNullOrEmpty(options.Config)) ProtocolSettings.Custom = customSetting; | ||
} | ||
|
||
private static void CustomApplicationSettings(CommandLineOptions options, Settings settings) | ||
{ | ||
var tempSetting = string.IsNullOrEmpty(options.Config) ? settings : new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration")); | ||
var customSetting = new Settings | ||
{ | ||
Logger = tempSetting.Logger, | ||
Storage = new StorageSettings | ||
{ | ||
Engine = options.DBEngine ?? tempSetting.Storage.Engine, | ||
Path = options.DBPath ?? tempSetting.Storage.Path | ||
}, | ||
P2P = tempSetting.P2P, | ||
UnlockWallet = new UnlockWalletSettings | ||
{ | ||
Path = options.Wallet ?? tempSetting.UnlockWallet.Path, | ||
Password = options.Password ?? tempSetting.UnlockWallet.Password | ||
}, | ||
Contracts = tempSetting.Contracts | ||
}; | ||
if (options.IsValid) Settings.Custom = customSetting; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be added back somehow.