public void Execute(string[] args, IWorker worker) { var parser = new ArgumentParser(args); parser.CheckIfCanBeExecuted(); if (args[0] == CommandNames.Help) { ShowHelp(args, worker); return; } var files = new FileSource().GetFiles(args[1]); var commandPool = files.Select(file => new CommandFactory().ChooseCommand(args[0], file, worker, args[2])).ToList(); if (!commandPool.Any(command => command.IsPlanningCommand())) { commandPool.ForEach(command => command.Execute()); return; } foreach (var command in commandPool) { try { command.Execute(); ShowPlan(command, worker); } catch (Exception e) { worker.WriteLine("Command " + command.Accept(new GetCommandNameVisitor()) + "cannot be executed for file" + command.Accept(new GetFilePathVisitor()) + "because of exception:\n" + e.Message); } } SaveChanges(files, worker, args.Contains("--backup-ignore")); }