private void AddDepLine(string configuration, Dep dep, bool isOn) { var path = Path.Combine(workspace, patchModule, Helper.YamlSpecFile); var moduleYamlFile = new ModuleYamlFile(new FileInfo(path)); var lines = moduleYamlFile.Lines; var configIndex = lines.FindIndex( l => l.StartsWith(configuration + ":") || l.StartsWith(configuration + " ")); var depsIndex = -1; for (var index = configIndex + 1; index < lines.Count && (lines[index].Length == 0 || lines[index].StartsWith(" ")); index++) { if (lines[index].EndsWith("deps:")) { depsIndex = index; break; } } if (depsIndex == -1) { lines.Insert(configIndex + 1, GetSpacesStart(lines, configIndex) + "deps:"); depsIndex = configIndex + 1; } var prefix = GetSpacesStart(lines, depsIndex) + (isOn ? "- " : "- -"); lines.Insert(depsIndex + 1, prefix + GetDepLine(dep)); moduleYamlFile.Save(path, lines); }
private void RemoveDepLine(string configuration, Dep dep, bool isOn) { var path = Path.Combine(workspace, patchModule, Helper.YamlSpecFile); var moduleYamlFile = new ModuleYamlFile(new FileInfo(path)); var lines = moduleYamlFile.Lines; var configIndex = lines.FindIndex( l => l.StartsWith(configuration + ":") || l.StartsWith(configuration + " ")); var depsIndex = -1; for (var index = configIndex + 1; index < lines.Count && lines[index].StartsWith(" "); index++) { if (lines[index].EndsWith("deps:")) { depsIndex = index; break; } } if (depsIndex == -1) { return; } for (var index = depsIndex + 1; index < lines.Count && lines[index].StartsWith(GetSpacesStart(lines, depsIndex)); index++) { var str = (isOn ? " - " : " - -") + dep.Name; if (lines[index].Contains(str + "/") || lines[index].Contains(str + "@") || lines[index].EndsWith(str)) { lines.RemoveAt(index); break; } } moduleYamlFile.Save(path, lines); }
public DepsPatcher(string workspace, string patchModule, Dep patchDep) { this.workspace = workspace; this.patchModule = patchModule; this.patchDep = patchDep; yamlPath = Path.Combine(workspace, patchModule, Helper.YamlSpecFile); if (!File.Exists(yamlPath)) { throw new CementException("module.yaml not found in " + yamlPath); } ModuleYamlFile.ReplaceTabs(yamlPath); }
private void ReplaceDepLine(string patchConfiguration, Dep was, Dep shouldBe) { var path = Path.Combine(workspace, patchModule, Helper.YamlSpecFile); var moduleYamlFile = new ModuleYamlFile(new FileInfo(path)); var lines = moduleYamlFile.Lines; var configIndex = lines.FindIndex(l => l.StartsWith(patchConfiguration + ":") || l.StartsWith(patchConfiguration + " ")); var depsIndex = lines.FindIndex(configIndex, line => line.EndsWith("deps:")); var removeIndex = lines.FindIndex(depsIndex, line => line.Contains(" " + was.Name + "/") || line.Contains(" " + was.Name + "@") || line.Contains(" " + was.Name + ":") || line.EndsWith(" " + was.Name)); ReplaceDepLine(was, shouldBe, removeIndex, lines, depsIndex); moduleYamlFile.Save(path, lines); }