refactor: Move Spark cmd opts to own file

This commit is contained in:
John Colvin committed 2023-04-14 13:18:28 -04:00
1 parent d7518cffe1
commit 94071b4889
2 files changed
+43 -33

No files matched your search

+5 -33
View File
@@ -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<CLIOptions>(argv).WithParsed(opts => {
Parser.Default.ParseArguments<SparkCmdOpts>(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;
}
}
}
}
@@ -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;
}
}
}