| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using System.IO.Abstractions; |
| | 4 | | using CommandLine; |
| | 5 | | using Mklinker.Abstractions; |
| | 6 | |
|
| | 7 | | namespace Mklinker.Commands { |
| | 8 | |
|
| | 9 | | [Verb("removelink", HelpText = "Removes link from config")] |
| | 10 | | class RemoveLinkCommand : GlobalOptions { |
| | 11 | |
|
| | 12 | | [Value(0, HelpText = "The targetPath matching entry you want to delete from config.", MetaName = "targetPath", Requi |
| 7 | 13 | | public string targetPath { get; private set; } |
| | 14 | |
|
| 0 | 15 | | public RemoveLinkCommand() : base() { } |
| | 16 | |
|
| 4 | 17 | | public RemoveLinkCommand(string targetPath, string path) : base(path) { |
| 2 | 18 | | this.targetPath = targetPath; |
| 2 | 19 | | } |
| | 20 | |
|
| 2 | 21 | | internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IPathResolver pathReso |
| 0 | 22 | | if (!configHandler.DoesConfigExist(path)) { |
| 0 | 23 | | console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config |
| 0 | 24 | | return; |
| | 25 | | } |
| | 26 | |
|
| 2 | 27 | | IConfig config = configHandler.LoadConfig(path); |
| 5 | 28 | | ConfigLink configLink = config.LinkList.FirstOrDefault(link => pathResolver.GetAbsoluteResolvedPath(link.targetPat |
| | 29 | |
|
| 3 | 30 | | if (configLink != null) { |
| 1 | 31 | | config.LinkList.Remove(configLink); |
| 1 | 32 | | console.WriteLine("\nSuccessfully removed link with targetPath '{0}'", targetPath); |
| | 33 | |
|
| 1 | 34 | | configHandler.SaveConfig(config, path); |
| 2 | 35 | | } else { |
| 1 | 36 | | console.WriteLine($"\nThe targetPath '{targetPath}' is invalid because it does not exist in config", IConsole.Co |
| 1 | 37 | | } |
| 2 | 38 | | } |
| | 39 | |
|
| | 40 | | } |
| | 41 | | } |