Created
January 13, 2019 19:47
-
-
Save dariusz-wozniak/7eb84157e4cb8d122f682a4052695df0 to your computer and use it in GitHub Desktop.
π« Filter Chocolatey upgrade log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
public class FilterChocoUpgradeLog | |
{ | |
public static void FilterAndWrite(string logToRead, string logToWrite) | |
{ | |
var linesToWrite = new List<string>(); | |
string[] lines = File.ReadAllLines(logToRead); | |
bool forceToAddLine = false; | |
foreach(var line in lines) | |
{ | |
if (line.StartsWith("Date-Time of Upgrading: ")) | |
{ | |
linesToWrite.Add(string.Empty); | |
linesToWrite.Add("-----------------------------------------"); | |
linesToWrite.Add("Choco short log for : " + line.Substring(24, 19)); | |
linesToWrite.Add("-----------------------------------------"); | |
linesToWrite.Add(string.Empty); | |
} | |
if (line.StartsWith("Chocolatey upgraded ")) | |
{ | |
forceToAddLine = true; | |
} | |
if (line.StartsWith("--")) | |
{ | |
forceToAddLine = false; | |
} | |
if (forceToAddLine) | |
{ | |
linesToWrite.Add(line); | |
} | |
} | |
linesToWrite.Add(string.Empty); | |
File.WriteAllLines(logToWrite, linesToWrite); | |
} | |
} | |
Console.WriteLine("Executing FilterChocoUpgradeLog script..."); | |
Console.WriteLine("Reading from: " + Env.ScriptArgs[0]); | |
Console.WriteLine("Writing to: " + Env.ScriptArgs[1]); | |
FilterChocoUpgradeLog.FilterAndWrite(Env.ScriptArgs[0], Env.ScriptArgs[1]); | |
Console.WriteLine("The script FilterChocoUpgradeLog has been finished successfully"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment