From 94071b4889c0f42b8639fc6df888041cedd83add Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 14 Apr 2023 09:57:24 -0400 Subject: [PATCH] refactor: Move Spark cmd opts to own file --- src/client/spark/App.xaml.cs | 38 +++------------------- src/client/spark/Spark.Cli/SparkCmdOpts.cs | 38 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 src/client/spark/Spark.Cli/SparkCmdOpts.cs diff --git a/src/client/spark/App.xaml.cs b/src/client/spark/App.xaml.cs index 386cc7c6e..291a2fe8a 100644 --- a/src/client/spark/App.xaml.cs +++ b/src/client/spark/App.xaml.cs @@ -5,9 +5,10 @@ namespace mbts.ui.shell { using CommandLine; using mbts.ui.native; + + using Spark.Cli; using System; - using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; @@ -21,7 +22,7 @@ namespace mbts.ui.shell { static readonly Mutex _mutex; ShellBootstrapper _runtime; - CLIOptions _opts; + SparkCmdOpts _opts; Process _stunnel_process; static App() { @@ -58,10 +59,10 @@ namespace mbts.ui.shell { } int exit_code = 1; - Parser.Default.ParseArguments(argv).WithParsed(opts => { + Parser.Default.ParseArguments(argv).WithParsed(opts => { _opts = opts; var opt_desc = TableFormatter.fmt_table( - typeof(CLIOptions).GetProperties() + typeof(SparkCmdOpts).GetProperties() .Select(p => (p.Name, p.GetValue(opts))), field_separator: "\n\t"); Log.Ui.info($"Running spark_client with options:\n\t{opt_desc}"); try { @@ -159,34 +160,5 @@ namespace mbts.ui.shell { stunnel_job_error = "Error starting stunnel: " + ex.Message; } } - - class CLIOptions { - [Option("multiple", HelpText = "Allow multple shells to run simultaneously")] - public bool allow_multiple_shells { get; set; } - - [Option("stunnel", HelpText = "Use stunnel")] - public bool stunnel { get; set; } - - [Option("no-stunnel", HelpText = "Don't use stunnel")] - public bool no_stunnel { - get => !stunnel; - set => stunnel = !value; - } - - [Option("user", HelpText = "The user with which to login")] - public string user { get; set; } - - [Option("password", HelpText = "The password with which to login")] - public string password { get; set; } - - [Option("restore-workspace", HelpText = "Whether or not to restore the user's last workspace", Default = true)] - public bool restore_workspace { get; set; } - - [Option("no-restore-workspace", HelpText = "Whether or not to restore the user's last workspace")] - public bool no_restore_workspace { - get => !restore_workspace; - set => restore_workspace = !value; - } - } } } diff --git a/src/client/spark/Spark.Cli/SparkCmdOpts.cs b/src/client/spark/Spark.Cli/SparkCmdOpts.cs new file mode 100644 index 000000000..c7ebb42c3 --- /dev/null +++ b/src/client/spark/Spark.Cli/SparkCmdOpts.cs @@ -0,0 +1,38 @@ +#nullable enable +namespace Spark.Cli { + using CommandLine; + + class SparkCmdOpts { + [Option("multiple", HelpText = "Allow multple shells to run simultaneously")] + public bool allow_multiple_shells { get; set; } + + [Option("stunnel", HelpText = "Use stunnel")] + public bool stunnel { get; set; } + + [Option("no-stunnel", HelpText = "Don't use stunnel")] + public bool no_stunnel { + get => !stunnel; + set => stunnel = !value; + } + + [Option("user", MetaValue = "USER", HelpText = "The user to login with")] + public string? user { get; set; } + + [Option("password", MetaValue = "PASS", HelpText = "The password to login with")] + public string? password { get; set; } + + [Option( + "restore-workspace", + HelpText = "Whether or not to restore the user's last workspace", + Default = true)] + public bool restore_workspace { get; set; } + + [Option( + "no-restore-workspace", + HelpText = "Whether or not to restore the user's last workspace")] + public bool no_restore_workspace { + get => !restore_workspace; + set => restore_workspace = !value; + } + } +}