| | 1 | | using System; |
| | 2 | | using System.IO.Abstractions; |
| | 3 | | using CommandLine; |
| | 4 | | using Mklinker.Abstractions; |
| | 5 | | using Mklinker.Commands; |
| | 6 | |
|
| | 7 | | namespace Mklinker { |
| | 8 | |
|
| | 9 | | class CommandExecutor : ICommandExecutor { |
| | 10 | |
|
| | 11 | | readonly IConsole console; |
| | 12 | | readonly IConfigHandler configHandler; |
| | 13 | | readonly IFileSystem fileSystem; |
| | 14 | | readonly IConfig defaultConfig; |
| | 15 | | readonly IArgumentParser argumentHandler; |
| | 16 | | readonly ILinker linker; |
| | 17 | | readonly IPathResolver pathResolver; |
| | 18 | |
|
| 6 | 19 | | public CommandExecutor (IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IConfig defaultConfi |
| 3 | 20 | | this.console = console; |
| 3 | 21 | | this.configHandler = configHandler; |
| 3 | 22 | | this.fileSystem = fileSystem; |
| 3 | 23 | | this.defaultConfig = defaultConfig; |
| 3 | 24 | | this.argumentHandler = argumentHandler; |
| 3 | 25 | | this.linker = linker; |
| 3 | 26 | | this.pathResolver = pathResolver; |
| 3 | 27 | | } |
| | 28 | |
|
| 3 | 29 | | void ICommandExecutor.Execute(params string[] args) { |
| | 30 | | // Parse commands |
| 6 | 31 | | var parser = new Parser(with => with.HelpWriter = console.Writer); |
| 3 | 32 | | var parserResult = parser.ParseArguments<AddLinkCommand, AddLinksCommand, AddVariableCommand, RemoveLinkCommand, R |
| | 33 | |
|
| 3 | 34 | | parserResult |
| 0 | 35 | | .WithParsed<IDefaultCommandHandler>(flag => flag.Execute(console, configHandler, fileSystem)) |
| 0 | 36 | | .WithParsed<ConfigCommand>(cmd => cmd.Execute(console, configHandler, defaultConfig, pathResolver)) |
| 0 | 37 | | .WithParsed<InteractiveCommand>(cmd => cmd.Execute (console, argumentHandler, this)) |
| 0 | 38 | | .WithParsed<LinkAllCommand>(cmd => cmd.Execute (console, configHandler, fileSystem, linker, pathResolver)) |
| 0 | 39 | | .WithParsed<AddLinkCommand>(cmd => cmd.Execute (console, configHandler, fileSystem, pathResolver)) |
| 0 | 40 | | .WithParsed<ValidateCommand>(cmd => cmd.Execute(console, configHandler, fileSystem, pathResolver)) |
| 0 | 41 | | .WithParsed<ListCommand>(cmd => cmd.Execute (console, configHandler, fileSystem, pathResolver)) |
| 0 | 42 | | .WithParsed<AddLinksCommand>(cmd => cmd.Execute(console, configHandler, fileSystem, pathResolver)) |
| 0 | 43 | | .WithParsed<ScanCommand>(cmd => cmd.Execute (console, fileSystem, pathResolver)) |
| 0 | 44 | | .WithParsed<RemoveLinkCommand>(cmd => cmd.Execute(console, configHandler, fileSystem, pathResolver)); |
| 3 | 45 | | } |
| | 46 | |
|
| | 47 | | } |
| | 48 | |
|
| | 49 | | } |