| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using CommandLine; |
| | 4 | | using Mklinker.Abstractions; |
| | 5 | |
|
| | 6 | | namespace Mklinker.Commands { |
| | 7 | |
|
| | 8 | | [Verb("config", HelpText = "Displays information about config file by default, but can create / delete / modify config |
| | 9 | | class ConfigCommand : GlobalOptions { |
| | 10 | |
|
| | 11 | | [Option ('c', "create", HelpText = "Creates a new config file if it does not exist", SetName = "Create")] |
| 14 | 12 | | public bool create { get; private set; } |
| | 13 | |
|
| | 14 | | [Option('d', "delete", HelpText = "Deleted config file if it exists", SetName = "Delete")] |
| 12 | 15 | | public bool delete { get; private set; } |
| | 16 | |
|
| 0 | 17 | | public ConfigCommand() : base() {} |
| | 18 | |
|
| 14 | 19 | | public ConfigCommand (bool create, bool delete, string path) : base(path) { |
| 7 | 20 | | this.create = create; |
| 7 | 21 | | this.delete = delete; |
| 7 | 22 | | } |
| | 23 | |
|
| 7 | 24 | | internal void Execute(IConsole console, IConfigHandler configHandler, IConfig defaultConfig, IPathResolver pathResol |
| 9 | 25 | | if (create) { |
| 3 | 26 | | if (configHandler.DoesConfigExist(path)) { |
| 1 | 27 | | console.WriteLine("Config already exists!", IConsole.ContentType.Negative); |
| 2 | 28 | | } else { |
| 1 | 29 | | console.WriteLine("Creating config '{0}'", path); |
| | 30 | |
|
| 1 | 31 | | configHandler.SaveConfig(defaultConfig, path); |
| 1 | 32 | | } |
| 9 | 33 | | } else if (delete) { |
| 3 | 34 | | if (configHandler.DoesConfigExist(path)) { |
| 1 | 35 | | console.WriteLine("Deleting config '{0}'", path); |
| 1 | 36 | | configHandler.DeleteConfig(path); |
| 2 | 37 | | } else { |
| 1 | 38 | | console.WriteLine($"Config '{path}' does not exist!", IConsole.ContentType.Negative); |
| 1 | 39 | | } |
| 5 | 40 | | } else { |
| 5 | 41 | | if (configHandler.DoesConfigExist(path)) { |
| 2 | 42 | | IConfig config = configHandler.LoadConfig(path); |
| | 43 | |
|
| 2 | 44 | | console.WriteLine(); |
| 2 | 45 | | console.WriteLine("### Metadata info ###", IConsole.ContentType.Header); |
| 2 | 46 | | console.WriteLine($"Path: {path}"); |
| 2 | 47 | | console.WriteLine($"Full path: {pathResolver.GetAbsoluteResolvedPath(path, config.Variables)}"); |
| 2 | 48 | | console.WriteLine($"Version: {config.Version}"); |
| 2 | 49 | | console.WriteLine(); |
| | 50 | |
|
| 2 | 51 | | console.WriteLine("### Variable info ###", IConsole.ContentType.Header); |
| 2 | 52 | | console.WriteLine("Total variables: " + config.Variables.Count); |
| 2 | 53 | | console.WriteLine(); |
| | 54 | |
|
| 2 | 55 | | console.WriteLine("### Link info ###", IConsole.ContentType.Header); |
| 2 | 56 | | console.WriteLine("Total links: " + config.LinkList.Count); |
| 3 | 57 | | console.WriteLine("Junction links: " + config.LinkList.Count(l => l.linkType == ConfigLink.LinkType.Junction)) |
| 3 | 58 | | console.WriteLine("Symbolic links: " + config.LinkList.Count(l => l.linkType == ConfigLink.LinkType.Symbolic)) |
| 3 | 59 | | console.WriteLine("Hard links: " + config.LinkList.Count(l => l.linkType == ConfigLink.LinkType.Hard)); |
| 3 | 60 | | } else { |
| 1 | 61 | | console.WriteLine("Config does not exist. You can create one with the --create option.", IConsole.ContentType. |
| 1 | 62 | | } |
| 3 | 63 | | } |
| 7 | 64 | | } |
| | 65 | |
|
| | 66 | | } |
| | 67 | |
|
| | 68 | | } |