Merged in sparkcmd_commandline (pull request #218)
RTM: Sparkcmd commandline Approved-by: Jake Norbut <jake.norbut@bluetradesys.com> Approved-by: Michael Harding <michael.harding@bluetradesys.com>
This commit is contained in:
commit
bb1571540a
9 files changed
+141
-121
No files matched your search
@@ -1,14 +1,19 @@
|
||||
using ManyConsole;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CommandLine;
|
||||
|
||||
namespace bts {
|
||||
public class Configcheck : ConsoleCommand {
|
||||
public Configcheck() {
|
||||
IsCommand("configcheck", "Ye olde Configcheck");
|
||||
HasAdditionalArguments(null, " [Keys to check]");
|
||||
}
|
||||
public override int Run(string[] args) {
|
||||
mbts.config.Configuration.configcheck(args.Length, args.ToArray());
|
||||
|
||||
[Verb("configcheck", HelpText="Ye olde Configcheck")]
|
||||
public class ConfigcheckOptions {
|
||||
[Value(0, MetaName="keys", HelpText="Keys to print")]
|
||||
public IEnumerable<string> keys { get; set; }
|
||||
}
|
||||
public class Configcheck {
|
||||
public static int Run(ConfigcheckOptions options) {
|
||||
var keys = options.keys.ToArray();
|
||||
mbts.config.Configuration.configcheck(keys.Length, keys);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ManyConsole {
|
||||
public static class ConsoleCommandEx {
|
||||
public static string get_argument(this ConsoleCommand _, string arg_name) {
|
||||
var arg = Environment.GetCommandLineArgs().FirstOrDefault(str => str.StartsWith("--"+arg_name));
|
||||
if (arg != null) {
|
||||
var parts = arg.Split(new[] { '=' }, 2);
|
||||
if (parts.Length > 1) {
|
||||
return parts[1];
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,32 +6,33 @@ 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 {
|
||||
bool _server = false;
|
||||
string _host;
|
||||
string _logfile;
|
||||
[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; }
|
||||
|
||||
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) {
|
||||
[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 {
|
||||
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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using bts.api.core;
|
||||
using bts.test;
|
||||
using ManyConsole;
|
||||
using CommandLine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,24 +8,27 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bts {
|
||||
class TailService : ConsoleCommand {
|
||||
[Verb("tail", HelpText="'console dsqa'")]
|
||||
class TailServiceOptions {
|
||||
[Option('m', "method", Required=true, HelpText = "'[ServiceName].[Method]' to call")]
|
||||
public string method { get;set; }
|
||||
|
||||
[Option('t', "time", HelpText="Include timestamp")]
|
||||
public bool time { get; set; }
|
||||
|
||||
[Option('p', "path", HelpText="Path inside the row to use for display. Ex: 'Id' or 'Name' ")]
|
||||
public string path { get; set; }
|
||||
|
||||
[Option('a', "all", HelpText="Include 'all' rows on every print")]
|
||||
public bool all { get; set; }
|
||||
}
|
||||
class TailService {
|
||||
static bool _all = false;
|
||||
static bool _timestamp = false;
|
||||
public TailService() {
|
||||
void ignore(string _) { }
|
||||
IsCommand("tailservice", "Tail updates to named service api. Ex: tail --method=SyntheticSecurityService.metadata");
|
||||
HasRequiredOption("method", "Service.method to tail", ignore);
|
||||
HasOption("time", "Include timestamp", _ => _timestamp = true);
|
||||
// The following are not implemented. If you need them get to work.
|
||||
HasOption("path", "Path inside the row to use for display. Ex: 'Id' or 'Name' ", ignore);
|
||||
HasOption("all", "Invlude 'all' rows on every print", _ => _all = true);
|
||||
HasAdditionalArguments(null, " [nothing]");
|
||||
}
|
||||
public override int Run(string[] remainingArguments) {
|
||||
var arg = this.get_argument("method");
|
||||
var split = arg.Split('.');
|
||||
public static int Run(TailServiceOptions o) {
|
||||
var split = o.method.Split('.');
|
||||
if (split.Length != 2) {
|
||||
Console.WriteLine("Try --method=[ServiceName].[Method]");
|
||||
Console.WriteLine("Try --method [ServiceName].[Method]");
|
||||
return -1;
|
||||
}
|
||||
tail(split[0], split[1]);
|
||||
|
||||
@@ -2,30 +2,29 @@ using bts.api;
|
||||
using bts.api.core;
|
||||
using bts.api.synthetic;
|
||||
using bts.test;
|
||||
using ManyConsole;
|
||||
using CommandLine;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace bts {
|
||||
public class ServiceTest : ConsoleCommand {
|
||||
bool _synthetic;
|
||||
bool _user;
|
||||
bool _admin;
|
||||
|
||||
public ServiceTest() {
|
||||
IsCommand("service", "Put code here for testing during service development");
|
||||
HasOption("synthetic", "Run synthetic test", _ => _synthetic = true);
|
||||
HasOption("user", "user test", _ => _user = true);
|
||||
HasOption("admin", "admin test", _ => _admin = true);
|
||||
}
|
||||
public override int Run(string[] remainingArguments) {
|
||||
if (_synthetic) {
|
||||
public class ServiceTestOptions {
|
||||
[Option(nameof(synthetic))]
|
||||
public bool synthetic { get; set; }
|
||||
[Option(nameof(user))]
|
||||
public bool user { get; set; }
|
||||
[Option(nameof(admin))]
|
||||
public bool admin { get; set; }
|
||||
}
|
||||
public class ServiceTest {
|
||||
public static int Run(ServiceTestOptions o) {
|
||||
if (o.synthetic) {
|
||||
synthetic_test();
|
||||
}
|
||||
if (_user) {
|
||||
if (o.user) {
|
||||
user_test();
|
||||
}
|
||||
if (_admin) {
|
||||
if (o.admin) {
|
||||
admin_test();
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using ManyConsole;
|
||||
using System.Reflection;
|
||||
using CommandLine;
|
||||
|
||||
namespace bts {
|
||||
|
||||
public class SettinsManagerCommand : ConsoleCommand {
|
||||
public SettinsManagerCommand() {
|
||||
IsCommand("SettingsManager", "Copy workspaces around");
|
||||
}
|
||||
[Verb("settingsmanager", HelpText="Copy workspaces around")]
|
||||
public class SettingsManagerOptions { }
|
||||
|
||||
public override int Run(string[] remainingArguments) {
|
||||
public class SettingsManagerCommand {
|
||||
public static int Run(SettingsManagerOptions _) {
|
||||
var asm = Assembly.Load("spark");
|
||||
var type = asm.GetType("bts.settings.SettingsManagerTool");
|
||||
var run = type.GetMethod("run", BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
using bts.test;
|
||||
using ManyConsole;
|
||||
using System;
|
||||
using mbts;
|
||||
using System.Collections.Generic;
|
||||
@@ -8,64 +7,73 @@ using bts.api.test;
|
||||
using System.Threading.Tasks;
|
||||
using mbts.config;
|
||||
using System.Linq;
|
||||
using CommandLine;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace sparkcmd {
|
||||
public class TestCommand : ConsoleCommand {
|
||||
uint _timeout = 0;
|
||||
uint _parallel = 1;
|
||||
bool _list;
|
||||
|
||||
TestType test_type = TestType.Unit;
|
||||
[Verb("test", HelpText="Run Tests")]
|
||||
public class TestCommandOptions {
|
||||
|
||||
bool self_contained = false;
|
||||
[Option('t', "timeout", HelpText="Timeout unit tets", Default=0u)]
|
||||
public uint timeout { get; set; }
|
||||
[Option('l', "list", HelpText="List tests")]
|
||||
public bool list { get; set; }
|
||||
[Option('i', "insular", HelpText="Tests run sparkd and use their own config (if specified)")]
|
||||
public bool self_contained { get; set; }
|
||||
|
||||
public TestCommand() {
|
||||
IsCommand("test", "Run managed unit tests");
|
||||
// i comes thorugh as "t" which seems daft.
|
||||
HasOption("t|timeout", "Timeout unit tests", i => _timeout = 10);
|
||||
HasOption<uint>("n|parallel", "How many tests to run in parallel", i => _parallel = i);
|
||||
HasOption("l|list", "List all tests", _ => _list = true);
|
||||
HasOption("unit","Run unit tests", _ => test_type = TestType.Unit);
|
||||
HasOption("system","Run system tests", _ => test_type = TestType.System);
|
||||
HasOption("shell","Run shell tests", _ => test_type = TestType.Shell);
|
||||
HasOption("i|insular|selfcontained", "Tests run sparkd and use their own config (if specified)", _ => self_contained = true);
|
||||
HasAdditionalArguments(null, " [Test List]");
|
||||
[Option("type", HelpText ="Run all tests of type [Unit|System|Shell]")]
|
||||
public TestType type { get; set; }
|
||||
|
||||
|
||||
[Value(1, MetaName="Tests", HelpText="Test list")]
|
||||
public IEnumerable<string> tests { get; set; }
|
||||
|
||||
}
|
||||
public static class TestCommand {
|
||||
static TestType test_type(string t) {
|
||||
switch(t.ToLower()) {
|
||||
case "unit": return TestType.Unit;
|
||||
case "system": return TestType.System;
|
||||
case "shell": return TestType.Shell;
|
||||
}
|
||||
return TestType.Unit;
|
||||
}
|
||||
|
||||
public override int Run(string[] tests) {
|
||||
if (_list) {
|
||||
list_tests();
|
||||
public static int Run(TestCommandOptions o) {
|
||||
Console.WriteLine(JsonConvert.SerializeObject(o));
|
||||
|
||||
if (o.list) {
|
||||
list_tests((o.type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Configuration.initialize_for_test();
|
||||
|
||||
if (_timeout == 0 && tests.Length == 1 && !self_contained) {
|
||||
if (o.timeout == 0 && o.tests.Count() == 1 && !o.self_contained) {
|
||||
//System.Threading.Thread.Sleep(5000);
|
||||
using (var trr = new TestResultReceiver(true)) {
|
||||
InProcessTestRunner.run_test_synchronously(tests[0], Enumerator, trr.get_reporter());
|
||||
InProcessTestRunner.run_test_synchronously(o.tests.First(), Enumerator, trr.get_reporter());
|
||||
trr.print_summary();
|
||||
return trr.ErrorCount;
|
||||
}
|
||||
}
|
||||
else if (tests.Length > 0) {
|
||||
return run_tests(Enumerator.match(tests));
|
||||
else if (o.tests.Count() > 0) {
|
||||
return run_tests(o, Enumerator.match(o.tests));
|
||||
}
|
||||
else {
|
||||
return run_tests(Enumerator.get_of_type(test_type));
|
||||
return run_tests(o, Enumerator.get_of_type(o.type));
|
||||
}
|
||||
}
|
||||
|
||||
Lazy<TestEnumerator> _enumerator = new Lazy<TestEnumerator>(() => new TestEnumerator("spark_test"));
|
||||
TestEnumerator Enumerator => _enumerator.Value;
|
||||
static Lazy<TestEnumerator> _enumerator = new Lazy<TestEnumerator>(() => new TestEnumerator("spark_test"));
|
||||
static TestEnumerator Enumerator => _enumerator.Value;
|
||||
|
||||
int run_tests(IEnumerable<TestMethod> tests) {
|
||||
static int run_tests(TestCommandOptions o, IEnumerable<TestMethod> tests) {
|
||||
var runner = new TestRunner();
|
||||
// waits for all child processes to exit or time out
|
||||
return runner.run_tests(tests, _timeout, self_contained);
|
||||
return runner.run_tests(tests, o.timeout, o.self_contained);
|
||||
}
|
||||
|
||||
void list_tests() {
|
||||
static void list_tests(TestType test_type) {
|
||||
Console.WriteLine("All tests: ");
|
||||
foreach (var t in Enumerator.get_groups_of_type(test_type)) {
|
||||
ConsoleEx.WriteLine(t.name, ConsoleColor.Green);
|
||||
|
||||
@@ -2,16 +2,39 @@
|
||||
using bts.api.core;
|
||||
using bts.api.synthetic;
|
||||
using bts.api.test;
|
||||
using ManyConsole;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using CommandLine;
|
||||
using bts;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace sparkcmd {
|
||||
class Program {
|
||||
|
||||
// static object option<T>(Func<T,int> run) {return run;}
|
||||
// static Type argType(object arg) {
|
||||
// return arg.GetType().GetGenericArguments().First();
|
||||
// }
|
||||
// static int Run(Func<IEnumerable<Error>,int> on_error, params object[] args) {
|
||||
// var types = args.Select(argType).ToArray();
|
||||
// var parse = CommandLine.Parser.Default.GetType().GetMethod("ParseArguments", BindingFlags.Public).MakeGenericMethod(types);
|
||||
// return 3;
|
||||
// }
|
||||
static int Main(string[] args) {
|
||||
mbts.utils.BTSNativeMethods.provide_command_line(args, args.Length);
|
||||
var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program));
|
||||
return ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out);
|
||||
// note: this can be made to infer the options type list from the list of delegates
|
||||
return Parser.Default
|
||||
.ParseArguments<ConfigcheckOptions,ScriptClientOptions,TailServiceOptions,ServiceTestOptions,SettingsManagerOptions,TestCommandOptions >(args)
|
||||
.MapResult<ConfigcheckOptions,ScriptClientOptions,TailServiceOptions,ServiceTestOptions,SettingsManagerOptions,TestCommandOptions,int>(
|
||||
Configcheck.Run,
|
||||
ScriptClientCommand.Run,
|
||||
TailService.Run,
|
||||
ServiceTest.Run,
|
||||
SettingsManagerCommand.Run,
|
||||
TestCommand.Run,
|
||||
errors => 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
<!--<Proto3 Include="**/*.proto" />-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ManyConsole" Version="1.0.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.4.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user