Add more tests + Split for Console.Out & Console.Error + Remove ShowHelp() method
MODIFY
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
WalletWasabi.Gui/CommandLine/CommandInterpreter.cs
@@ -9,11 +9,13 @@ namespace WalletWasabi.Gui.CommandLine
{
public class CommandInterpreter
{
- public CommandInterpreter(TextWriter textWriter)
+ public CommandInterpreter(TextWriter outW, TextWriter errorW)
{
- TextWriter = textWriter;
+ Out = outW;
+ Error = errorW;
}
- private TextWriter TextWriter { get; }
+ private TextWriter Out { get; }
+ private TextWriter Error { get; }
/// <returns>If the GUI should run or not.</returns>
public async Task<bool> ExecuteCommandsAsync(string[] args, Command mixerCommand, Command passwordFinderCommand)
@@ -26,7 +28,7 @@ namespace WalletWasabi.Gui.CommandLine
return true;
}
- var suite = new CommandSet("wassabee")
+ var suite = new CommandSet("wassabee", Out, Error)
{
"Usage: wassabee [OPTIONS]+",
"Launches Wasabi Wallet.",
@@ -48,7 +50,7 @@ namespace WalletWasabi.Gui.CommandLine
if (showHelp)
{
ShowVersion();
- ShowHelp(suite.Options);
+ await suite.RunAsync(new string[] { "--help" });
return false;
}
else if (showVersion)
@@ -72,20 +74,10 @@ namespace WalletWasabi.Gui.CommandLine
private void ShowVersion()
{
- TextWriter.WriteLine($"Wasabi Client Version: {Constants.ClientVersion}");
- TextWriter.WriteLine($"Compatible Coordinator Version: {Constants.ClientSupportBackendVersionText}");
- TextWriter.WriteLine($"Compatible Bitcoin Core and Bitcoin Knots Versions: {Constants.BitcoinCoreVersion}");
- TextWriter.WriteLine($"Compatible Hardware Wallet Interface Version: {Constants.HwiVersion}");
- }
-
- private void ShowHelp(OptionSet p)
- {
- TextWriter.WriteLine();
- TextWriter.WriteLine("Usage: wassabee [OPTIONS]+");
- TextWriter.WriteLine("Launches Wasabi Wallet.");
- TextWriter.WriteLine();
- TextWriter.WriteLine("Options:");
- p.WriteOptionDescriptions(TextWriter);
+ Out.WriteLine($"Wasabi Client Version: {Constants.ClientVersion}");
+ Out.WriteLine($"Compatible Coordinator Version: {Constants.ClientSupportBackendVersionText}");
+ Out.WriteLine($"Compatible Bitcoin Core and Bitcoin Knots Versions: {Constants.BitcoinCoreVersion}");
+ Out.WriteLine($"Compatible Hardware Wallet Interface Version: {Constants.HwiVersion}");
}
}
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -67,7 +67,7 @@ namespace WalletWasabi.Gui
private static bool ShouldRunGui(string[] args)
{
var daemon = new Daemon(Global);
- var interpreter = new CommandInterpreter(Console.Out);
+ var interpreter = new CommandInterpreter(Console.Out, Console.Error);
var executionTask = interpreter.ExecuteCommandsAsync(
args,
new MixerCommand(daemon),

MODIFY
WalletWasabi.Tests/UnitTests/GUI/CommandInterpreterTest.cs
WalletWasabi.Tests/UnitTests/GUI/CommandInterpreterTest.cs
@@ -9,22 +9,69 @@ namespace WalletWasabi.Tests.UnitTests.GUI
public class CommandInterpreterTest
{
[Fact]
- public async void CommandInterpreterShowsHelpAsync()
+ public async void ShowsHelpAsync()
{
- var textWriter = new StringWriter();
- var c = new CommandInterpreter(textWriter);
- await c.ExecuteCommandsAsync(new string[] { "wassabee", "--help" }, new Command("mixer"), new Command("findpassword"));
+ (StringWriter outW, StringWriter errorW, CommandInterpreter c) = Make();
+ await c.ExecuteCommandsAsync(new string[] { "--help" }, new Command("mixer"), new Command("findpassword"));
+
+ Assert.Equal(
+ @"Usage: wassabee [OPTIONS]+
+Launches Wasabi Wallet.
+
+ -h, --help Displays help page and exit.
+ -v, --version Displays Wasabi version and exit.
+
+Available commands are:
+
+ mixer
+ findpassword
+",
+ outW.ToString());
+
+ Assert.Equal("", errorW.ToString());
+ }
+
+ [Fact]
+ public async void ShowsVersionAsync()
+ {
+ (StringWriter outW, StringWriter errorW, CommandInterpreter c) = Make();
+ await c.ExecuteCommandsAsync(new string[] { "--version" }, new Command("mixer"), new Command("findpassword"));
Assert.Equal(
$@"Wasabi Client Version: {Constants.ClientVersion}
Compatible Coordinator Version: {Constants.ClientSupportBackendVersionText}
Compatible Bitcoin Core and Bitcoin Knots Versions: {Constants.BitcoinCoreVersion}
Compatible Hardware Wallet Interface Version: {Constants.HwiVersion}
+",
+ outW.ToString());
-Usage: wassabee [OPTIONS]+
-Launches Wasabi Wallet.
+ Assert.Equal("", errorW.ToString());
+ }
+
+ [Fact]
+ public async void InvalidCommandAsync()
+ {
+ (StringWriter outW, StringWriter errorW, CommandInterpreter c) = Make();
+ await c.ExecuteCommandsAsync(new string[] { "invalid" }, new Command("mixer"), new Command("findpassword"));
-Options:
+ Assert.Equal("", outW.ToString());
+ Assert.Equal(
+ @"wassabee: Unknown command: invalid
+wassabee: Use `wassabee help` for usage.
+",
+ errorW.ToString());
+ }
+
+ [Fact]
+ public async void InvalidCommandWithHelpAsync()
+ {
+ (StringWriter outW, StringWriter errorW, CommandInterpreter c) = Make();
+ await c.ExecuteCommandsAsync(new string[] { "invalid", "--help" }, new Command("mixer"), new Command("findpassword"));
+
+ Assert.Equal($@"Wasabi Client Version: {Constants.ClientVersion}
+Compatible Coordinator Version: {Constants.ClientSupportBackendVersionText}
+Compatible Bitcoin Core and Bitcoin Knots Versions: {Constants.BitcoinCoreVersion}
+Compatible Hardware Wallet Interface Version: {Constants.HwiVersion}
Usage: wassabee [OPTIONS]+
Launches Wasabi Wallet.
@@ -35,8 +82,19 @@ Available commands are:
mixer
findpassword
+", outW.ToString());
+ Assert.Equal(
+ @"wassabee: Unknown command: invalid
+wassabee: Use `wassabee help` for usage.
",
- textWriter.ToString());
+ errorW.ToString());
+ }
+
+ private static (StringWriter, StringWriter, CommandInterpreter) Make()
+ {
+ var outW = new StringWriter();
+ var errorW = new StringWriter();
+ return (outW, errorW, new CommandInterpreter(outW, errorW));
}
}
}

Add more tests + Split for Console.Out & Console.Error + Remove ShowHelp() method