Make Mono.Options async
MODIFY
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
@@ -2,13 +2,14 @@ using Mono.Options;
using System;
using System.Linq;
using System.Runtime.InteropServices;
+using System.Threading.Tasks;
using WalletWasabi.Helpers;
namespace WalletWasabi.Gui.CommandLine
{
public static class CommandInterpreter
{
- public static bool ExecuteCommands(string[] args)
+ public static async Task<bool> ExecuteCommandsAsync(string[] args)
{
var showHelp = false;
var showVersion = false;
@@ -43,7 +44,7 @@ namespace WalletWasabi.Gui.CommandLine
};
EnsureBackwardCompatibilityWithOldParameters(ref args);
- if (suite.Run(args) == 0)
+ if (await suite.RunAsync(args) == 0)
{
return false;
}

MODIFY
WalletWasabi.Gui/CommandLine/MixerCommand.cs
WalletWasabi.Gui/CommandLine/MixerCommand.cs
using Mono.Options;
using System;
using System.Collections.Generic;
+using System.Threading.Tasks;
using WalletWasabi.Logging;
namespace WalletWasabi.Gui.CommandLine
@@ -38,7 +39,7 @@ namespace WalletWasabi.Gui.CommandLine
};
}
- public override int Invoke(IEnumerable<string> args)
+ public override async Task<int> InvokeAsync(IEnumerable<string> args)
{
var error = false;
LogLevel? logLevel = null;
@@ -82,7 +83,7 @@ namespace WalletWasabi.Gui.CommandLine
if (!error && !ShowHelp)
{
- Daemon.RunAsync(WalletName, logLevel, MixAll, KeepMixAlive, Silent).GetAwaiter().GetResult();
+ await Daemon.RunAsync(WalletName, logLevel, MixAll, KeepMixAlive, Silent);
}
}
catch (Exception)

MODIFY
WalletWasabi.Gui/CommandLine/PasswordFinderCommand.cs
WalletWasabi.Gui/CommandLine/PasswordFinderCommand.cs
using Mono.Options;
using System;
using System.Collections.Generic;
+using System.Threading.Tasks;
using WalletWasabi.KeyManagement;
namespace WalletWasabi.Gui.CommandLine
@@ -36,7 +37,7 @@ namespace WalletWasabi.Gui.CommandLine
v => ShowHelp = true}};
}
- public override int Invoke(IEnumerable<string> args)
+ public override Task<int> InvokeAsync(IEnumerable<string> args)
{
var error = false;
try
@@ -70,7 +71,7 @@ namespace WalletWasabi.Gui.CommandLine
error = true;
}
Environment.Exit(error ? 1 : 0);
- return 0;
+ return Task.FromResult(0);
}
}
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -27,7 +27,7 @@ namespace WalletWasabi.Gui
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
- if (!CommandInterpreter.ExecuteCommands(args))
+ if (!await CommandInterpreter.ExecuteCommandsAsync(args))
{
return;
}

MODIFY
WalletWasabi/Mono/Command.cs
WalletWasabi/Mono/Command.cs
using System;
using System.Collections.Generic;
using System.Text;
+using System.Threading.Tasks;
namespace Mono.Options
{
@@ -200,11 +201,11 @@ namespace Mono.Options
return value.ToString();
}
- public virtual int Invoke(IEnumerable<string> arguments)
+ public virtual Task<int> InvokeAsync(IEnumerable<string> arguments)
{
var rest = Options?.Parse(arguments) ?? arguments;
Run?.Invoke(rest);
- return 0;
+ return Task.FromResult(0);
}
}
}

MODIFY
WalletWasabi/Mono/CommandSet.cs
WalletWasabi/Mono/CommandSet.cs
@@ -160,6 +160,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
+using System.Threading.Tasks;
using MessageLocalizerConverter = System.Converter<string, string>;
namespace Mono.Options
@@ -400,7 +401,7 @@ namespace Mono.Options
}
}
- public int Run(IEnumerable<string> arguments)
+ public async Task<int> RunAsync(IEnumerable<string> arguments)
{
if (arguments is null)
throw new ArgumentNullException(nameof(arguments));
@@ -424,7 +425,7 @@ namespace Mono.Options
{
if (ShowHelp)
{
- return Help.Invoke(extra);
+ return await Help.InvokeAsync(extra);
}
Out.WriteLine(Options.MessageLocalizer($"Use `{Suite} help` for usage."));
return 1;
@@ -440,12 +441,12 @@ namespace Mono.Options
if (command.Options?.Contains("help") ?? true)
{
extra.Add("--help");
- return command.Invoke(extra);
+ return await command.InvokeAsync(extra);
}
command.Options.WriteOptionDescriptions(Out);
return 0;
}
- return command.Invoke(extra);
+ return await command.InvokeAsync(extra);
}
public Command GetCommand(List<string> extra)

MODIFY
WalletWasabi/Mono/HelpCommand.cs
WalletWasabi/Mono/HelpCommand.cs
using System;
using System.Collections.Generic;
using System.Text;
+using System.Threading.Tasks;
namespace Mono.Options
{
@@ -168,7 +169,7 @@ namespace Mono.Options
{
}
- public override int Invoke(IEnumerable<string> arguments)
+ public override async Task<int> InvokeAsync(IEnumerable<string> arguments)
{
var extra = new List<string>(arguments ?? new string[0]);
if (extra.Count == 0)
@@ -207,7 +208,7 @@ namespace Mono.Options
command.Options.WriteOptionDescriptions(CommandSet.Out);
return 0;
}
- return command.Invoke(new[] { "--help" });
+ return await command.InvokeAsync(new[] { "--help" });
}
private List<KeyValuePair<string, Command>> GetCommands()

Make Mono.Options async