Skip to content

Instantly share code, notes, and snippets.

@dariusz-wozniak
Created January 13, 2019 19:47
Show Gist options
  • Save dariusz-wozniak/7eb84157e4cb8d122f682a4052695df0 to your computer and use it in GitHub Desktop.
Save dariusz-wozniak/7eb84157e4cb8d122f682a4052695df0 to your computer and use it in GitHub Desktop.
🍫 Filter Chocolatey upgrade log
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