public override void Specify() { when("repeatedly dispatching a command", delegate { var trace = new StringWriter(); arrange(delegate { ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "1", "-y", "2" }, new StringWriter()); ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-x", "3" }, new StringWriter()); ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move", "-y", "4" }, new StringWriter()); ConsoleCommandDispatcher.DispatchCommand(SomeProgram.GetCommands(trace), new[] { "move" }, new StringWriter()); }); then("all parameters are evaluated independently", delegate { Expect.That(trace.ToString()).ContainsInOrder( "You walk to 1, 2 and find a maze of twisty little passages, all alike.", "You walk to 3, 0 and find a maze of twisty little passages, all alike.", "You walk to 0, 4 and find a maze of twisty little passages, all alike.", "You walk to 0, 0 and find a maze of twisty little passages, all alike." ); }); }); }
static int Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var serviceScope = host.Services.CreateScope()) { var services = serviceScope.ServiceProvider; try { TerraformIoService = services.GetRequiredService <TerraformIoService>(); var commands = GetCommands(); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred."); return(-1); } } }
#pragma warning restore 0649 internal int Run(string[] args) { try { var extraArgs = Initialize(args); Compose(); _logger.Information("NVika {Version}", typeof(Program).GetTypeInfo().Assembly.GetName().Version); return(ConsoleCommandDispatcher.DispatchCommand(_commands, extraArgs.ToArray(), Console.Out)); } catch (NVikaException exception) { _logger.Fatal(exception, "An unexpected error occurred:"); return(exception.ExitCode); } catch (Exception exception) { if (_logger == null) { Console.WriteLine("Error: logger is not configured."); Console.WriteLine($"An unexpected error occurred:\r\n{exception}"); } else { _logger.Fatal(exception, "An unexpected error occurred:"); } return(ExitCodes.UnknownError); } }
private static int Main(string[] args) { Console.WriteLine($"{ProgramName} {CurrentVersion}"); Console.InputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8; HandleExceptions(); var commands = new ConsoleCommand[] { new GetFriends(), new GetGroupFriends(), new InviteFriends(), new SendVkMessage(), }; try { return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); } catch (Exception ex) { Console.WriteLine(@"Unhandled exception: {0}", ex.Message); return(-1); } }
public override void Specify() { when("a simple command is run", delegate { StringBuilder result = new StringBuilder(); arrange(delegate { var sw = new StringWriter(result); ConsoleCommandDispatcher.DispatchCommand( new ConsoleCommand[] { new SomeCommand() }, new string[] { "thecommand" }, sw); }); then("the output includes a summary of the command", delegate { expect(() => result.ToString() == @" Executing thecommand (One-line description): FieldA : abc PropertyB : def PropertyC : null PropertyD : 1, 2, 3 "); }); }); }
static int Main(string[] args) { try { Program p = new Program(); var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); } catch (ReflectionTypeLoadException ex) { StringBuilder sb = new StringBuilder(); foreach (Exception exSub in ex.LoaderExceptions) { sb.AppendLine(exSub.Message); if (exSub is FileNotFoundException) { FileNotFoundException exFileNotFound = exSub as FileNotFoundException; if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) { sb.AppendLine("Fusion Log:"); sb.AppendLine(exFileNotFound.FusionLog); } } sb.AppendLine(); } string errorMessage = sb.ToString(); Console.WriteLine(errorMessage); //Display or log the error based on your application. return(0); } }
public override void Specify() { var trace = new StringWriter(); when("the user types in input which is rejected by NDesk.Options", delegate { var lastError = arrange(() => ConsoleCommandDispatcher.DispatchCommand( new ConsoleCommand[] { new SomeCommandWithAParameter() }, new[] { "some", "/a" }, trace)); then("the error output gives the error message and typical help", delegate { expect(() => lastError != 0); expect(() => trace.ToString().Contains("Missing required value for option '/a'")); expect(() => trace.ToString().Contains(TextWithinExpectedUsageHelp)); expect(() => !trace.ToString().ToLower().Contains("ndesk.options")); expect(() => !trace.ToString().ToLower().Contains("exception")); }); }); when("a command causes other unexpected errors", delegate { then("the exception passes through", delegate { Assert.Throws <InvalidAsynchronousStateException>(() => ConsoleCommandDispatcher.DispatchCommand( new ConsoleCommand[] { new SomeCommandThrowingAnException(), }, new string[0], trace)); }); }); }
public Func <int> RunConsoleModeCommand(string[] lines, bool inputIsFromUser, ConsoleCommand command, TextWriter outputWriter = null) { var injectedInputStream = new MemoryStream(); var fakeConsoleWriter = outputWriter ?? new StringWriter(); var fakeConsoleReader = new StreamReader(injectedInputStream); var consoleModeCommand = new ConsoleModeCommand( () => new ConsoleCommand[] { command }, fakeConsoleWriter, fakeConsoleReader); arrange(delegate { var injectedInput = new StreamWriter(injectedInputStream); foreach (var line in lines) { injectedInput.WriteLine(line); } injectedInput.Flush(); injectedInputStream.Seek(0, SeekOrigin.Begin); }); IConsoleRedirectionDetection redirectionDetection = A.Fake <IConsoleRedirectionDetection>(); arrange(() => consoleModeCommand.SetConsoleRedirectionDetection(redirectionDetection)); arrange(() => A.CallTo(() => redirectionDetection.IsInputRedirected()).Returns(!inputIsFromUser)); return(() => ConsoleCommandDispatcher.DispatchCommand(new ConsoleCommand[] { consoleModeCommand }, new string[0], fakeConsoleWriter)); }
private static int Main(string[] args) { // locate any commands in the assembly (or use an IoC container, or whatever source) var commands = GetCommands(); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); }
public override void Specify() { given("exactly one command is loaded", () => { var exampleCommand = new ExampleCommand(); var commands = new ConsoleCommand[] { exampleCommand }; when("no parameters are specified", () => { var output = new StringWriter(); var exitCode = arrange(() => ConsoleCommandDispatcher.DispatchCommand(commands, new string[0], output)); then_the_command_runs_without_tracing_parameter_information(output, exitCode); then("the command's property is not set", () => { expect(() => exampleCommand.Foo == null); }); }); when("the only parameter specified is the command", () => { var output = new StringWriter(); var exitCode = arrange(() => ConsoleCommandDispatcher.DispatchCommand(commands, new[] { "Example" }, output)); then_the_command_runs_without_tracing_parameter_information(output, exitCode); then("the command's property is not set", () => { expect(() => exampleCommand.Foo == null); }); }); when("the only parameter specified is not the command", () => { var output = new StringWriter(); var exitCode = arrange(() => ConsoleCommandDispatcher.DispatchCommand(commands, new[] { "/f=bar" }, output)); then_the_command_runs_without_tracing_parameter_information(output, exitCode); then("the command's property is set", () => { expect(() => exampleCommand.Foo == "bar"); }); }); when("both the command and an extra parameter are specified", () => { var output = new StringWriter(); var exitCode = arrange(() => ConsoleCommandDispatcher.DispatchCommand(commands, new[] { "Example", "/f=bar" }, output)); then_the_command_runs_without_tracing_parameter_information(output, exitCode); then("the command's property is set", () => { expect(() => exampleCommand.Foo == "bar"); }); }); }); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(App)); ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out); }
internal static int Main(string[] args) { Console.Write(GetHeader()); int rc = 42; // generic failure try { // locate any commands in the assembly (or use an IoC container, or whatever source) var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)); // then run them. rc = ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out); if (rc == 0) { ConsoleColor save = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Succeeded."); Console.ForegroundColor = save; } } catch (Exception e) { e.Dump(Console.Out); rc = 99; } return(rc); }
public static int Main(string[] args) { DefaultDataPath = "/media/ekwav/Daten3/dev/lifenizer/data"; var commands = GetCommands(); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); }
static void Main(string[] args) { int result; try { var commandToExecute = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)); result = ConsoleCommandDispatcher.DispatchCommand(commandToExecute, args, Console.Out); } catch (Exception e) { result = -1; Console.Error.WriteLine(e.Message); if (e.InnerException != null) { Console.Error.WriteLine(e.InnerException.Message); } } if (Debugger.IsAttached) { Debugger.Break(); } Environment.Exit(result); }
private void ShouldShowHelpWhenRequested(List <ConsoleCommand> commands, string[] consoleArguments) { var writer = new StringWriter(); when("we call a command, asking for help", delegate { var commandC = new TestCommand() .IsCommand("command-c", "one line description for C") .HasAdditionalArguments(0, "<remaining> <args>") .HasOption("o|option=", "option description", v => { }); commands.Add(commandC); var exitCode = arrange(() => ConsoleCommandDispatcher.DispatchCommand(commands, consoleArguments, writer)); then("the output contains a all help available for that command", delegate { var output = writer.ToString(); Expect.That(output).ContainsInOrder( commandC.Command, commandC.OneLineDescription, commandC.RemainingArgumentsHelpText, "-o", "--option", "option description"); }); then("the process exit code is non-zero", () => expect(() => exitCode == -1)); }); }
static int Main(string[] args) { return(ConsoleCommandDispatcher.DispatchCommand( ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)), args, Console.Out)); }
static int Main(string[] args) { try { var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)); foreach (var c in commands) { c.SkipsCommandSummaryBeforeRunning(); } args = SupportCompatibilityMode(args, commands); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); } catch (Exception exc) { Console.Error.WriteLine(exc); return(1); } finally { if (!Console.IsOutputRedirected && OwnsConsole()) { Console.WriteLine("Press any key to exit ..."); Console.ReadKey(); } } }
static int Main(string[] args) { bool displayHeader = true; var preset = new OptionSet() .Add("no|nologo", n => displayHeader = false); preset.Parse(args); if (displayHeader) { Console.WriteLine(GetHeader()); } try { // locate any commands in the assembly (or use an IoC container, or whatever source) var commands = GetCommands(); // then run them. int rc = ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out); if (rc == 0) { Console.WriteLine("Succeeded."); }//if return(rc); } catch (Exception e) { e.Dump(Console.Out); return(99); }//try }
static int Main(string[] args) { var commands = ConsoleCommandDispatcher.FindCommandsInAllLoadedAssemblies(); var exitCode = ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out); return(exitCode); }
/// <summary>Runs the application.</summary> /// <param name="args">The arguments.</param> /// <returns>Result code.</returns> public int Run(string[] args) { try { WriteAppInfo(); LibZContainer.RegisterEncoder("deflate", DefaultCodecs.DeflateEncoder, true); LibZContainer.RegisterCodec("zlib", DefaultCodecs.ZLibEncoder, DefaultCodecs.ZLibDecoder); ConfigureLogging(); LoadPlugins(); RegisterPlugins(); try { Log.Trace("LibZ started"); var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(GetType()); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); } finally { Log.Trace("LibZ stopped"); } } catch (Exception e) { Log.Error("{0}: {1}", e.GetType().Name, e.Message); Log.Debug(e.StackTrace); return(1); } }
static void Main(string[] args) { var processed = false; Console.Write("Initializing ChronoSpark Time Manager..."); SparkLogic.Initialize(); Console.WriteLine("DONE!"); while (!processed)//!exit { Console.Write("ChronoSpark => "); processed = false; var cmd = "run-console"; ReminderControl defaultController = new ReminderControl(); NoActiveTaskListener noActiveTaskListener = new NoActiveTaskListener(); IntervalPassedListener intervalPassedListener = new IntervalPassedListener(); TimeToReportListener timeToReportListener = new TimeToReportListener(); noActiveTaskListener.Suscribe(defaultController); intervalPassedListener.Suscribe(defaultController); timeToReportListener.Suscribe(defaultController); ThreadPool.QueueUserWorkItem(delegate { defaultController.ActivateReminders(); }); String[] cdmArgs = cmd.Split(' '); var commands = GetCommands(); ConsoleModeCommand consoleRunner = new ConsoleModeCommand(GetCommands); commands = commands.Concat(new[] { consoleRunner }); ConsoleCommandDispatcher.DispatchCommand(commands, cdmArgs, Console.Out); processed = true; } }
public static void Start(string url, Type start) { Log.Info("Connecting to SharePoint..."); using (var site = new SPSite(url)) { using (Web = site.OpenWeb()) { Log.Info("Ensuring lists..."); ListBuilder.EnsureLists(Web); Log.Info("Let the game begin!"); Game = new Game(Web); new Thread(() => { while (true) { lock (Game) { if (!Game.Run) { break; } Game.Ping(); Monitor.Wait(Game, TimeSpan.FromSeconds(5)); if (!Game.Run) { break; } } } }).Start(); var commands = GetCommands(start); commands = commands.Concat(GetCommands(typeof(ExtremeSharePoint))); while (true) { var line = Console.ReadLine(); var cmd = new string[] {}; if (line != null) { cmd = line.Split(' '); } var result = ConsoleCommandDispatcher.DispatchCommand(commands, cmd, Console.Out); if (result < -1) { break; } } lock (Game) { Game.Run = false; Monitor.Pulse(Game); } } } }
public static int Main(string[] args) { StartUp(); var commands = GetCommands(); return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); }
private static int Main(string[] args) { var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)); var result = ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out); return(result); }
static int Main(string[] args) { var startup = new Startup(); var serviceProvider = startup.BuildContainer(); var list = serviceProvider.GetService <ICommandList>(); return(ConsoleCommandDispatcher.DispatchCommand(list.Commands, args, Console.Out)); }
private static int Main(string[] args) { // locate any commands in the assembly var commands = GetCommands(); // run the command for the console input return(ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out)); }
public override void Specify() { given("a no-op command that requires a parameter", delegate() { string result = null; var noopCommand = new TestCommand() .IsCommand("required", "This command has a required parameter") .HasOption("ignored=", "An extra option.", v => { }) .HasRequiredOption("f|foo=", "This foo to use.", v => result = v) .SkipsCommandSummaryBeforeRunning(); when_the_command_is_ran_without_the_parameter_then_the_console_gives_error_output(noopCommand, "foo"); when("that command is ran with the parameter", delegate() { StringWriter output = new StringWriter(); var exitCode = arrange(() => ConsoleCommandDispatcher.DispatchCommand(noopCommand, new[] { "required", "-foo", "bar" }, output)); then("the exit code indicates the call succeeded", delegate() { expect(() => exitCode == 0); }); then("the option is actually received", delegate() { expect(() => result == "bar"); }); }); }); given("a command that requires an integer parameter", () => { int result = 0; var requiresInteger = arrange(() => new TestCommand() .IsCommand("parse-int") .HasRequiredOption <int>("value=", "The integer value", v => result = v)); when("the command is passed an integer value", () => { StringWriter output = new StringWriter(); var exitCode = arrange(() => ConsoleCommandDispatcher.DispatchCommand(requiresInteger, new[] { "parse-int", "-value", "42" }, output)); then("the command is told the parameter", () => { expect(() => result == 42); }); then("the return value is success", () => expect(() => exitCode == 0)); }); when_the_command_is_ran_without_the_parameter_then_the_console_gives_error_output(requiresInteger, "value"); }); }
public override void Specify() { given("we have some commands", delegate { var firstcommand = new TestCommand().IsCommand("command-a", "oneline description a"); var secondCommand = new TestCommand().IsCommand("command-b", "oneline description b"); var commands = new ConsoleCommand[] { firstcommand, secondCommand }.ToList(); var writer = new StringWriter(); when("we dispatch the commands with no arguments", delegate { arrange(() => ConsoleCommandDispatcher.DispatchCommand(commands, new string[0], writer)); then("the output contains a list of available commands", delegate { var output = writer.ToString(); Expect.That(output).ContainsInOrder( firstcommand.Command, firstcommand.OneLineDescription, secondCommand.Command, secondCommand.OneLineDescription); }); }); when("we call a command, asking for help", delegate { var commandC = new TestCommand() .IsCommand("command-c", "one line description for C") .HasAdditionalArguments(0, "<remaining> <args>") .HasOption("o|option=", "option description", v => { }); commands.Add(commandC); arrange(() => ConsoleCommandDispatcher.DispatchCommand(commands, new string[] { commandC.Command, "/?" }, writer)); then("the output contains a all help available for that command", delegate { var output = writer.ToString(); Expect.That(output).ContainsInOrder( commandC.Command, commandC.OneLineDescription, commandC.RemainingArgumentsHelpText, "-o", "--option", "option description"); }); }); }); }
public static void Main(string[] args) { // Process Operation try { var commands = ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(MainClass)); ConsoleCommandDispatcher.DispatchCommand(commands, args, Console.Out); } catch (Exception e) { Console.WriteLine("Unable to process command..."); } }
static int Main(string[] args) { Console.Title = "YOLOv4"; GradientEngine.UseEnvironmentFromVariable(); TensorFlowSetup.Instance.EnsureInitialized(); return(ConsoleCommandDispatcher.DispatchCommand( ConsoleCommandDispatcher.FindCommandsInSameAssemblyAs(typeof(Program)), args, Console.Out)); }