internal void Execute(IConsole console, IConfigHandler configHandler, IConfig defaultConfig, IPathResolver pathResolver) { if (create) { if (configHandler.DoesConfigExist(path)) { console.WriteLine("Config already exists!", IConsole.ContentType.Negative); } else { console.WriteLine("Creating config '{0}'", path); configHandler.SaveConfig(defaultConfig, path); } } else if (delete) { if (configHandler.DoesConfigExist(path)) { console.WriteLine("Deleting config '{0}'", path); configHandler.DeleteConfig(path); } else { console.WriteLine($"Config '{path}' does not exist!", IConsole.ContentType.Negative); } } else { if (configHandler.DoesConfigExist(path)) { IConfig config = configHandler.LoadConfig(path); console.WriteLine(); console.WriteLine("### Metadata info ###", IConsole.ContentType.Header); console.WriteLine($"Path: {path}"); console.WriteLine($"Full path: {pathResolver.GetAbsoluteResolvedPath(path, config.Variables)}"); console.WriteLine($"Version: {config.Version}"); console.WriteLine(); console.WriteLine("### Variable info ###", IConsole.ContentType.Header); console.WriteLine("Total variables: " + config.Variables.Count); console.WriteLine(); console.WriteLine("### Link info ###", IConsole.ContentType.Header); console.WriteLine("Total links: " + config.LinkList.Count); console.WriteLine("Junction links: " + config.LinkList.Count(l => l.linkType == ConfigLink.LinkType.Junction)); console.WriteLine("Symbolic links: " + config.LinkList.Count(l => l.linkType == ConfigLink.LinkType.Symbolic)); console.WriteLine("Hard links: " + config.LinkList.Count(l => l.linkType == ConfigLink.LinkType.Hard)); } else { console.WriteLine("Config does not exist. You can create one with the --create option.", IConsole.ContentType.Negative); } } }
public void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); Variable existingVariable = config.Variables.FirstOrDefault(variable => variable.name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (existingVariable == null) { config.Variables.Add(new Variable(name, value)); console.WriteLine($"Added new variable '{ name }' with value '{ value }'"); configHandler.SaveConfig(config, path); } else { if (!force) { console.WriteLine($"A variable with the name '{ name }' already exists", IConsole.ContentType.Negative); } else { existingVariable.value = value; console.WriteLine($"Replaced existing variable value for '{ name }' with '{ value }'"); configHandler.SaveConfig(config, path); } } }
internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IPathResolver pathResolver) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); CreateLinks(console, configHandler, fileSystem, pathResolver, config, sourceDirectoryPath, targetDirectoryPath); }
internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, ILinker linker, IPathResolver pathResolver) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); console.WriteLine("\nCreating links based on config..."); int successes = 0; // Allow linkers verbose output if flag is set for this command linker.verbose = verbose; foreach (ConfigLink configLink in config.LinkList) { string resolvedSourcePath = pathResolver.GetAbsoluteResolvedPath(configLink.sourcePath, config.Variables); string resolvedTargetPath = pathResolver.GetAbsoluteResolvedPath(configLink.targetPath, config.Variables); CreateSubDirectories(console, fileSystem, pathResolver, config, resolvedTargetPath); if (fileSystem.Directory.Exists(resolvedTargetPath) || fileSystem.File.Exists(resolvedTargetPath)) { console.Write($"Path '{configLink.targetPath}' already exists", IConsole.ContentType.Negative); if (verbose) { console.Write($" (resolved to '{resolvedTargetPath}')", IConsole.ContentType.Negative); } console.WriteLine(); } else if (linker.CreateLink(resolvedSourcePath, resolvedTargetPath, configLink.linkType)) { successes++; } } console.WriteLine("\n### Finished! Created {0} / {1} links ###", successes, config.LinkList.Count); }
internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IPathResolver pathResolver) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); if (!displayVariables) { foreach (ConfigLink configLink in config.LinkList) { string absoluteSourcePathString = ""; string absoluteTargetPathString = ""; if (displayAbsolutePaths) { absoluteSourcePathString = $"\n\t\t => { pathResolver.GetAbsoluteResolvedPath(configLink.sourcePath, config.Variables) }"; absoluteTargetPathString = $"\n\t\t => { pathResolver.GetAbsoluteResolvedPath(configLink.targetPath, config.Variables) }"; } console.WriteLine($"\n" + $"{ configLink.linkType.ToString() } link:\n" + $"\t- Source: { configLink.sourcePath }{ absoluteSourcePathString }\n" + $"\t- Target: { configLink.targetPath }{ absoluteTargetPathString }\n"); } } else { foreach (Variable variable in config.Variables) { console.WriteLine($"\n { variable.ToString() }"); } } if (config.LinkList.Count == 0) { console.WriteLine("Config is empty"); } }
public void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); Variable existingVariable = config.Variables.FirstOrDefault(variable => variable.name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (existingVariable == null) { console.WriteLine($"A variable with name '{ name }' does not exist", IConsole.ContentType.Negative); } else { config.Variables.Remove(existingVariable); configHandler.SaveConfig(config, path); console.WriteLine($"Variable with name '{ name }' has been removed"); } }
internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IPathResolver pathResolver) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); ConfigLink configLink = config.LinkList.FirstOrDefault(link => pathResolver.GetAbsoluteResolvedPath(link.targetPath, config.Variables).Equals(pathResolver.GetAbsoluteResolvedPath(targetPath, config.Variables))); if (configLink != null) { config.LinkList.Remove(configLink); console.WriteLine("\nSuccessfully removed link with targetPath '{0}'", targetPath); configHandler.SaveConfig(config, path); } else { console.WriteLine($"\nThe targetPath '{targetPath}' is invalid because it does not exist in config", IConsole.ContentType.Negative); } }
internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IPathResolver pathResolver) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); // Force forward slash sourcePath = sourcePath.Replace('\\', '/'); targetPath = targetPath.Replace('\\', '/'); string formattedSourcePath = pathResolver.GetAbsoluteResolvedPath(sourcePath, config.Variables); string formattedTargetPath = pathResolver.GetAbsoluteResolvedPath(targetPath, config.Variables); if (!force && !fileSystem.File.Exists(formattedSourcePath) && !fileSystem.Directory.Exists(formattedSourcePath)) { console.WriteLine($"\nThe sourcePath '{sourcePath}' is invalid because it does not exist", IConsole.ContentType.Negative); return; } if (!force && config.LinkList.Any(link => pathResolver.GetAbsoluteResolvedPath(link.targetPath, config.Variables).Equals(formattedTargetPath))) { console.WriteLine($"\nThe targetPath '{targetPath}' is invalid because it already exists in config file", IConsole.ContentType.Negative); return; } config.LinkList.Add(new ConfigLink(sourcePath, targetPath, linkType)); configHandler.SaveConfig(config, path); console.WriteLine($"\nAdded new { linkType.ToString() } link to config file: \n" + $"Source: '{ sourcePath }'\n" + $"Target: '{ targetPath }'"); }
internal void Execute(IConsole console, IConfigHandler configHandler, IFileSystem fileSystem, IPathResolver pathResolver) { if (!configHandler.DoesConfigExist(path)) { console.WriteLine($"Config '{ path }' does not exist. Type 'help config' in order to see how you create a config file.", IConsole.ContentType.Negative); return; } IConfig config = configHandler.LoadConfig(path); bool isValid = true; foreach (ConfigLink configLink in config.LinkList) { string resolvedSourcePath = pathResolver.GetAbsoluteResolvedPath(configLink.sourcePath, config.Variables); string resolvedTargetPath = pathResolver.GetAbsoluteResolvedPath(configLink.targetPath, config.Variables); bool validation1 = ValidateExistence(fileSystem, resolvedSourcePath); bool validation2 = ValidateLinkType(fileSystem, resolvedSourcePath, configLink.linkType); bool validation3 = ValidateDuplicate(pathResolver, config, resolvedTargetPath); if (displayAll || !validation1 || !validation2 || !validation3) { console.WriteLine($"\n{ configLink.ToString() }"); isValid = false; } if (!validation1 || displayAll) { console.WriteLine($"\t# Source path exists: { (validation1 ? "Yes" : "No") }", validation1 ? IConsole.ContentType.Positive : IConsole.ContentType.Negative); } if (!validation2 || displayAll) { console.WriteLine($"\t# Link type acceptable: { (validation2 ? "Yes" : "No") }", validation2 ? IConsole.ContentType.Positive : IConsole.ContentType.Negative); } if (!validation3 || displayAll) { console.WriteLine($"\t# Duplicate target path exists: { (validation3 ? "False" : "True") }", validation3 ? IConsole.ContentType.Positive : IConsole.ContentType.Negative); } } if (config.LinkList.Count == 0) { console.WriteLine("Config is empty"); } else if (isValid) { console.WriteLine("Config is 100% valid"); } }