Clean Daemon command line
MODIFY
WalletWasabi.Gui/CommandLine/Daemon.cs
WalletWasabi.Gui/CommandLine/Daemon.cs
@@ -13,20 +13,12 @@ using WalletWasabi.Logging;
namespace WalletWasabi.Gui.CommandLine
{
- public static class Daemon
+ public static class CommandInterpreter
{
- public static async Task<bool> RunAsyncReturnTrueIfContinueWithGuiAsync(string[] args)
+ public static void ExecuteCommands(string[] args)
{
- var continueWithGui = true;
- var silent = false;
-
var showHelp = false;
var showVersion = false;
- LogLevel? logLevel = null;
- string walletName = null;
- var doMix = false;
- var mixAll = false;
- var keepMixAlive = false;
try
{
@@ -39,60 +31,58 @@ namespace WalletWasabi.Gui.CommandLine
OptionSet options = null;
var suite = new CommandSet("wassabee") {
"Usage: wassabee [OPTIONS]+",
- "Available commands are:",
+ "Launches Wasabi Wallet.",
"",
- { "v|version", "Displays Wasabi version and exit.", x => showVersion = x != null},
- new Command("mix", "Start mixing without the GUI with the specified wallet.")
- {
- Options = new OptionSet() {
- { "v|version", "Displays Wasabi version and exit.", x => showVersion = x != null},
{ "h|help", "Displays help page and exit.", x => showHelp = x != null},
- { "s|silent", "Do not log to the standard outputs.", x => silent = x != null},
- { "l|loglevel=", "Sets the level of verbosity for the log TRACE|INFO|WARNING|DEBUG|ERROR.", x => {
- var normalized = x?.ToLower()?.Trim();
- if(normalized == "info") logLevel = LogLevel.Info;
- else if(normalized == "warning") logLevel = LogLevel.Warning;
- else if(normalized == "error") logLevel = LogLevel.Error;
- else if(normalized == "trace") logLevel = LogLevel.Trace;
- else if(normalized == "debug") logLevel = LogLevel.Debug;
- else {
- Console.WriteLine("ERROR: Log level not recognized.");
- showHelp = true;
- }
- }},
- { "w|wallet=", "The specified wallet file.", x => {
- walletName = x?.Trim();
- }},
- { "mixall", "Mix once even if the coin reached the target anonymity set specified in the config file.", x => mixAll = x != null},
- { "keepalive", "Don't exit the software after mixing has been finished, rather keep mixing when new money arrives.", x => keepMixAlive = x != null},
- },
- Run = _=> doMix = true
- },
+ { "v|version", "Displays Wasabi version and exit.", x => showVersion = x != null},
+ "",
+ "Available commands are:",
+ "",
+ new MixerCommand(),
new PasswordFinderCommand()
};
suite.Run(args);
if (showHelp)
{
- continueWithGui = false;
ShowHelp(options);
- return continueWithGui;
+ return;
}
else if (showVersion)
{
- continueWithGui = false;
ShowVersion();
- return continueWithGui;
+ return;
}
}
finally
- {
- if (silent)
{
Native.DettachParentConsole();
}
}
+ private static void ShowVersion()
+ {
+ Console.WriteLine($"Wasabi Client Version: {Constants.ClientVersion}");
+ Console.WriteLine($"Compatible Coordinator Version: {Constants.BackendMajorVersion}");
+ }
+
+ private static void ShowHelp(OptionSet p)
+ {
+ ShowVersion();
+ Console.WriteLine();
+ Console.WriteLine("Usage: wassabee [OPTIONS]+");
+ Console.WriteLine("Launches Wasabi Wallet.");
+ Console.WriteLine();
+ Console.WriteLine("Options:");
+ p.WriteOptionDescriptions(Console.Out);
+ }
+
+ }
+
+ class Daemon
+ {
+ internal static async Task RunAsync(string walletName, LogLevel? logLevel, bool mixAll, bool keepMixAlive, bool silent)
+ {
Logger.InitializeDefaults(Path.Combine(Global.DataDir, "Logs.txt"));
if (logLevel.HasValue)
@@ -114,15 +104,13 @@ namespace WalletWasabi.Gui.CommandLine
KeyManager keyManager = null;
if (walletName != null)
{
- continueWithGui = false;
-
var walletFullPath = Global.GetWalletFullPath(walletName);
var walletBackupFullPath = Global.GetWalletBackupFullPath(walletName);
if (!File.Exists(walletFullPath) && !File.Exists(walletBackupFullPath))
{
// The selected wallet is not available any more (someone deleted it?).
Logger.LogCritical("The selected wallet doesn't exsist, did you delete it?", nameof(Daemon));
- return continueWithGui;
+ return;
}
try
@@ -132,18 +120,14 @@ namespace WalletWasabi.Gui.CommandLine
catch (Exception ex)
{
Logger.LogCritical(ex, nameof(Daemon));
- return continueWithGui;
+ return;
}
}
- if (doMix)
- {
- continueWithGui = false;
-
if (keyManager is null)
{
Logger.LogCritical("Wallet was not supplied. Add --wallet {WalletName}", nameof(Daemon));
- return continueWithGui;
+ return;
}
string password = null;
@@ -159,7 +143,7 @@ namespace WalletWasabi.Gui.CommandLine
else
{
Logger.LogCritical($"Wrong password. {count} attempts left. Exiting...");
- return continueWithGui;
+ return;
}
count--;
}
@@ -199,9 +183,6 @@ namespace WalletWasabi.Gui.CommandLine
await Global.ChaumianClient.DequeueAllCoinsFromMixAsync();
}
- return continueWithGui;
- }
-
private static async Task TryQueueCoinsToMixAsync(bool mixAll, string password)
{
try
@@ -220,22 +201,73 @@ namespace WalletWasabi.Gui.CommandLine
Logger.LogWarning(ex, nameof(Daemon));
}
}
+ }
- private static void ShowVersion()
+ internal class MixerCommand : Command
+ {
+ public string LoggingLevel { get; set; }
+ public string WalletName { get; set; }
+ public bool Silent { get; set; }
+ public bool MixAll { get; set; }
+ public bool KeepMixAlive { get; set; }
+ public bool ShowHelp { get; set; }
+
+ public MixerCommand()
+ : base("mix", "Start mixing without the GUI with the specified wallet.")
{
- Console.WriteLine($"Wasabi Client Version: {Constants.ClientVersion}");
- Console.WriteLine($"Compatible Coordinator Version: {Constants.BackendMajorVersion}");
+ Options = new OptionSet() {
+ "usage: mix --wallet:wallet-file-path --mixall --keepalive loglevel:log-level",
+ "",
+ "Start mixing without the GUI with the specified wallet.",
+ "eg: mix --wallet:/home/user/.walletwasabi/client/Wallets/MyWallet.json --mixall --keepalive loglevel:info",
+
+ { "h|help", "Displays help page and exit.", x => ShowHelp = x != null},
+ { "s|silent", "Do not log to the standard outputs.", x => Silent = x != null},
+ { "l|loglevel=", "Sets the level of verbosity for the log TRACE|INFO|WARNING|DEBUG|ERROR.", x => LoggingLevel = x },
+ { "w|wallet=", "The specified wallet file.", x => WalletName = x?.ToLower() },
+ { "mixall", "Mix once even if the coin reached the target anonymity set specified in the config file.", x => MixAll = x != null},
+ { "keepalive", "Don't exit the software after mixing has been finished, rather keep mixing when new money arrives.", x => KeepMixAlive = x != null},
+ };
}
- private static void ShowHelp(OptionSet p)
+ public override int Invoke(IEnumerable<string> args)
{
- ShowVersion();
- Console.WriteLine();
- Console.WriteLine("Usage: wassabee [OPTIONS]+");
- Console.WriteLine("Launches Wasabi Wallet.");
- Console.WriteLine();
- Console.WriteLine("Options:");
- p.WriteOptionDescriptions(Console.Out);
+ var error = false;
+ LogLevel? logLevel = null;
+ try
+ {
+ var extra = Options.Parse(args);
+ if (ShowHelp)
+ {
+ Options.WriteOptionDescriptions(CommandSet.Out);
+ }
+ else if (!string.IsNullOrEmpty(LoggingLevel))
+ {
+ var normalized = LoggingLevel.Trim();
+ if(normalized == "info") logLevel = LogLevel.Info;
+ else if(normalized == "warning") logLevel = LogLevel.Warning;
+ else if(normalized == "error") logLevel = LogLevel.Error;
+ else if(normalized == "trace") logLevel = LogLevel.Trace;
+ else if(normalized == "debug") logLevel = LogLevel.Debug;
+ else {
+ Console.WriteLine("ERROR: Log level not recognized.");
+ Options.WriteOptionDescriptions(CommandSet.Out);
+ error = true;
+ }
+ }
+
+ if(!error && !ShowHelp)
+ {
+ Daemon.RunAsync(WalletName, logLevel, MixAll, KeepMixAlive, Silent).GetAwaiter().GetResult();
+ }
+ }
+ catch(Exception)
+ {
+ Console.WriteLine($"commands: There was a problem interpreting the command, please review it.");
+ error = true;
+ }
+ Environment.Exit(error ? 1 : 0);
+ return 0;
}
}
}

MODIFY
WalletWasabi.Gui/CommandLine/PasswordFinder.cs
WalletWasabi.Gui/CommandLine/PasswordFinder.cs
@@ -9,7 +9,6 @@ using WalletWasabi.Helpers;
namespace WalletWasabi.Gui.CommandLine
{
-
internal class PasswordFinderCommand : Command
{
public string Secret { get; set; }

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -27,10 +27,11 @@ namespace WalletWasabi.Gui
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
- if (!await Daemon.RunAsyncReturnTrueIfContinueWithGuiAsync(args))
+ if(args.Length > 0)
{
- return;
+ CommandInterpreter.ExecuteCommands(args);
}
+
BuildAvaloniaApp()
.BeforeStarting(async builder =>
{

Clean Daemon command line