| | 1 | | using System; |
| | 2 | | using System.IO.Abstractions; |
| | 3 | | using CommandLine; |
| | 4 | | using Mklinker.Abstractions; |
| | 5 | |
|
| | 6 | | namespace Mklinker.Commands { |
| | 7 | |
|
| | 8 | | [Verb ("list", HelpText = "Lists all the links or variables in the config")] |
| | 9 | | class ListCommand : GlobalOptions { |
| | 10 | |
|
| | 11 | | [Option('v', "variables", HelpText = "Will display variables instead", Required = false, Default = false)] |
| 6 | 12 | | public bool displayVariables { get; private set; } |
| | 13 | |
|
| | 14 | | [Option('a', "absolute", HelpText = "Will display absolute paths with variables resolved", Required = false, Default |
| 0 | 15 | | public bool displayAbsolutePaths { get; private set; } |
| | 16 | |
|
| 0 | 17 | | public ListCommand() : base() {} |
| | 18 | |
|
| 6 | 19 | | public ListCommand(bool displayVariables, string path) : base(path) { |
| 3 | 20 | | this.displayVariables = displayVariables; |
| 3 | 21 | | } |
| | 22 | |
|
| 3 | 23 | | internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IPathResolver pathReso |
| 0 | 24 | | if (!configHandler.DoesConfigExist(path)) { |
| 0 | 25 | | console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config |
| 0 | 26 | | return; |
| | 27 | | } |
| | 28 | |
|
| 3 | 29 | | IConfig config = configHandler.LoadConfig(path); |
| | 30 | |
|
| 5 | 31 | | if (!displayVariables) { |
| 12 | 32 | | foreach (ConfigLink configLink in config.LinkList) { |
| 2 | 33 | | string absoluteSourcePathString = ""; |
| 2 | 34 | | string absoluteTargetPathString = ""; |
| | 35 | |
|
| 0 | 36 | | if (displayAbsolutePaths) { |
| 0 | 37 | | absoluteSourcePathString = $"\n\t\t => { pathResolver.GetAbsoluteResolvedPath(configLink.sourcePath, config |
| 0 | 38 | | absoluteTargetPathString = $"\n\t\t => { pathResolver.GetAbsoluteResolvedPath(configLink.targetPath, config |
| 0 | 39 | | } |
| | 40 | |
|
| 2 | 41 | | console.WriteLine($"\n" + |
| 2 | 42 | | $"{ configLink.linkType.ToString() } link:\n" + |
| 2 | 43 | | $"\t- Source: { configLink.sourcePath }{ absoluteSourcePathString }\n" + |
| 2 | 44 | | $"\t- Target: { configLink.targetPath }{ absoluteTargetPathString }\n"); |
| 2 | 45 | | } |
| 3 | 46 | | } else { |
| 9 | 47 | | foreach (Variable variable in config.Variables) { |
| 2 | 48 | | console.WriteLine($"\n { variable.ToString() }"); |
| 2 | 49 | | } |
| 1 | 50 | | } |
| | 51 | |
|
| 3 | 52 | | if (config.LinkList.Count == 0) |
| 2 | 53 | | console.WriteLine("Config is empty"); |
| 3 | 54 | | } |
| | 55 | |
|
| | 56 | | } |
| | 57 | |
|
| | 58 | | } |