示例#1
0
 public static IEnumerable <ICommand> NextCommand()
 {
     while (true)
     {
         yield return(CommandHandlerFactory.Create(Output.ReadLine()));
     }
 }
示例#2
0
        private static void PerformCommand()
        {
            if (CommandIsNotAllowed())
            {
                return;
            }

            CommandExecutionResult result = null;

            try
            {
                result = CommandHandlerFactory
                         .Create(_executionContext.Command.CommandType)
                         .Execute(_executionContext.Command.Parameters,
                                  _executionContext.CurrentScreen.Model);
            }
            catch (Exception exception)
            {
                ExceptionScreen(exception);
                return;
            }

            _executionContext.CurrentScreen = result.NextScreenType.HasValue
                ? ScreenFactory.CreateScreen(_render, result.NextScreenType.Value, result.Model)
                : null;

            _executionContext.Command = null;

            _render.Clear();
        }
示例#3
0
 public async Task run(string[] args)
 {
     var types = LoadTypes();
     await Parser.Default.ParseArguments(args, types)
     .MapResult(
         (dynamic opts) => _factory.Create(opts).RunCommand(opts),
         err => Decimal.MinusOne);
 }
示例#4
0
        public void CreatesHandler()
        {
            object testResult = new object();
            CommandHandlerFactory testSubject = new CommandHandlerFactory(t => testResult);

            object result = testSubject.Create(typeof(string));

            Assert.Same(testResult, result);
        }
示例#5
0
        static void Main(string[] args)
        {
            var  command = new Command();
            bool isHelp  = args.Any(x => x == "-?");
            var  success = Parser.Default.ParseArguments(args, command);

            if (!success || isHelp)
            {
                if (!isHelp && args.Length > 0)
                {
                    Console.Error.WriteLine("error parsing command line");
                }
            }


            var factory        = new CommandHandlerFactory();
            var commandHandler = factory.Create(command);

            commandHandler.Execute(command);
        }
示例#6
0
 private void ExecuteCommand(ConsoleCommand command) =>
 _commandHandlerFactory
 .Create(command.Name)
 .Execute(command.Path);