コード例 #1
0
        private CommandRun buildRun(Queue <string> queue, string commandName)
        {
            try
            {
                object input = null;

                if (BeforeBuild != null)
                {
                    input = tryBeforeBuild(queue, commandName);
                }

                var command = Build(commandName);

                if (input == null)
                {
                    input = command.Usages.BuildInput(queue, _commandCreator);
                }

                var run = new CommandRun
                {
                    Command = command,
                    Input   = input
                };

                ConfigureRun(run);

                return(run);
            }
            catch (InvalidUsageException e)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "Invalid usage");


                if (e.Message.IsNotEmpty())
                {
                    ConsoleWriter.Write(ConsoleColor.Yellow, e.Message);
                }

                Console.WriteLine();
            }
            catch (Exception e)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "Error parsing input");
                ConsoleWriter.Write(ConsoleColor.Yellow, e.ToString());

                Console.WriteLine();
            }

            return(HelpRun(commandName));
        }
コード例 #2
0
ファイル: CommandFactory.cs プロジェクト: aidanjryan/oakton
        private CommandRun buildRun(Queue <string> queue, string commandName)
        {
            var usages = new UsageGraph(_commandTypes[commandName]);

            try
            {
                var input = usages.BuildInput(queue, _commandCreator);

                BeforeBuild?.Invoke(commandName, input);

                var command = Build(commandName);

                var run = new CommandRun
                {
                    Command = command,
                    Input   = input
                };

                ConfigureRun(run);

                return(run);
            }
            catch (InvalidUsageException e)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "Invalid usage");


                if (e.Message.IsNotEmpty())
                {
                    ConsoleWriter.Write(ConsoleColor.Yellow, e.Message);
                }

                Console.WriteLine();
            }
            catch (Exception e)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "Error parsing input");
                ConsoleWriter.Write(ConsoleColor.Yellow, e.ToString());

                Console.WriteLine();
            }

            return(HelpRun(commandName));
        }
コード例 #3
0
        private CommandRun buildRun(Queue <string> queue, string commandName)
        {
            var command = Build(commandName);

            // this is where we'll call into UsageGraph?
            try
            {
                var usageGraph = command.Usages;
                var input      = usageGraph.BuildInput(queue);

                var run = new CommandRun
                {
                    Command = command,
                    Input   = input
                };

                ConfigureRun(run);

                return(run);
            }
            catch (InvalidUsageException e)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "Invalid usage");


                if (e.Message.IsNotEmpty())
                {
                    ConsoleWriter.Write(ConsoleColor.Yellow, e.Message);
                }

                Console.WriteLine();
            }
            catch (Exception e)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "Error parsing input");
                ConsoleWriter.Write(ConsoleColor.Yellow, e.ToString());

                Console.WriteLine();
            }

            return(HelpRun(commandName));
        }
コード例 #4
0
ファイル: CommandExecutor.cs プロジェクト: swimtver/oakton
        private static async Task <int> execute(CommandRun run)
        {
            bool success;

            try
            {
                success = await run.Execute();
            }
            catch (CommandFailureException e)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "ERROR: " + e.Message);

                return(1);
            }
            catch (Exception ex)
            {
                ConsoleWriter.Write(ConsoleColor.Red, "ERROR: " + ex);

                return(1);
            }

            return(success ? 0 : 1);
        }