Skip to content

Commit 8bd79d1

Browse files
committed
Fix: run without interactive in mac and linux support
1 parent 9004da9 commit 8bd79d1

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/Neo.CLI/CLI/MainService.CommandLine.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public partial class MainService
2121
{
2222
public int OnStartWithCommandLine(string[] args)
2323
{
24-
RootCommand rootCommand = new(Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>()!.Title)
24+
var rootCommand = new RootCommand(Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>()!.Title)
2525
{
2626
new Option<string>(["-c", "--config","/config"], "Specifies the config file."),
2727
new Option<string>(["-w", "--wallet","/wallet"], "The path of the neo3 wallet [*.json]."),
2828
new Option<string>(["-p", "--password" ,"/password"], "Password to decrypt the wallet, either from the command line or config file."),
29+
new Option<bool>(["--background","/background"], "Run the service in background."),
2930
new Option<string>(["--db-engine","/db-engine"], "Specify the db engine."),
3031
new Option<string>(["--db-path","/db-path"], "Specify the db path."),
3132
new Option<string>(["--noverify","/noverify"], "Indicates whether the blocks need to be verified when importing."),
@@ -72,7 +73,9 @@ private static void CustomProtocolSettings(CommandLineOptions options, ProtocolS
7273

7374
private static void CustomApplicationSettings(CommandLineOptions options, Settings settings)
7475
{
75-
var tempSetting = string.IsNullOrEmpty(options.Config) ? settings : new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration"));
76+
var tempSetting = string.IsNullOrEmpty(options.Config)
77+
? settings
78+
: new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration"));
7679
var customSetting = new Settings
7780
{
7881
Logger = tempSetting.Logger,

src/Neo.ConsoleService/ConsoleServiceBase.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private void OnScCommand(string action)
522522
}
523523

524524
string arguments;
525-
if (action == "/install")
525+
if (action == "install")
526526
{
527527
var fileName = Process.GetCurrentProcess().MainModule!.FileName;
528528
arguments = $"create {ServiceName} start= auto binPath= \"{fileName}\"";
@@ -551,13 +551,38 @@ private void OnScCommand(string action)
551551
}
552552
}
553553

554+
private void WaitForShutdown()
555+
{
556+
_running = true;
557+
try
558+
{
559+
_shutdownTokenSource.Token.WaitHandle.WaitOne();
560+
}
561+
catch (OperationCanceledException)
562+
{
563+
// Expected when shutdown is triggered
564+
}
565+
_running = false;
566+
}
567+
554568
public void Run(string[] args)
555569
{
570+
if (args.Contains("--background") || args.Contains("/background"))
571+
{
572+
if (OnStart(args)) WaitForShutdown(); // run without console input
573+
OnStop();
574+
return;
575+
}
576+
556577
if (Environment.UserInteractive)
557578
{
558-
if (args.Length == 1 && (args[0] == "/install" || args[0] == "/uninstall"))
579+
if (args.Length == 1 && (args[0] == "--install" || args[0] == "/install"))
580+
{
581+
OnScCommand("install");
582+
}
583+
else if (args.Length == 1 && (args[0] == "--uninstall" || args[0] == "/uninstall"))
559584
{
560-
OnScCommand(args[0]);
585+
OnScCommand("uninstall");
561586
}
562587
else
563588
{

0 commit comments

Comments
 (0)