Replace ManyConsole with CommandLineParser

This commit is contained in:
Eric Harding committed 2019-04-02 15:00:02 -04:00
1 parent 16acc4f5b0
commit 8793c6c527
9 files changed
+139 -116

No files matched your search

+19 -14
View File
@@ -6,32 +6,37 @@ using System.Reflection;
using System.Threading.Tasks;
using System.Reactive.Linq;
using System.Reactive;
using ManyConsole;
using System.Linq;
using CommandLine;
namespace sparkcmd {
public class ScriptClientCommand : ConsoleCommand {
[Verb("script", HelpText="Remote control for shell diagnostic host")]
public class ScriptClientOptions {
[Option('s', "server", HelpText="Run a script server for testing.")]
public bool server { get; set; }
[Option('h', "host", HelpText="Connect to {host}")]
public string host { get; set; }
[Option('f', "fromfile", HelpText="Read commands from file instead of stdin")]
public string file { get; set; }
}
public class ScriptClientCommand {
bool _server = false;
string _host;
string _logfile;
public ScriptClientCommand() {
IsCommand("script", "Remote control for shell diagnostic host");
HasOption("s|server", "Run a script server for testing.", x => _server = true);
HasOption("h|host", "Connect to {host}", h => _host = h);
HasOption("f|fromfile", "Read commands from file instead of stdin", f => _logfile = f);
}
public override int Run(string[] args) {
if (_server) {
public static int Run(ScriptClientOptions o) {
if (o.server) {
ScriptClient.runserver();
}
else {
var host = string.IsNullOrEmpty(_host) ? args.First() : _host;
if (string.IsNullOrEmpty(_logfile) && File.Exists(_logfile)) {
ScriptClient.start(host, File.OpenRead(_logfile));
if (string.IsNullOrEmpty(o.file) && File.Exists(o.file)) {
ScriptClient.start(o.host, File.OpenRead(o.file));
}
else {
ScriptClient.start(host, Console.OpenStandardInput());
ScriptClient.start(o.host, Console.OpenStandardInput());
}
}
return 0;