public OpenTelemetryLogsFolderCommand() : base("OpenTelemetryLogsFolder", "opens the folder that contains the telemetry log files") { var telLogFolderPath = this.Option("-p|--path", $"opens the folder that contains the telemetry log files. Default value: '{KnownStrings.TelemetryLogFolder}'", CommandOptionType.SingleOrNoValue); this.OnExecute(async() => { var folderFullpath = telLogFolderPath.HasValue() ? new PathHelper().GetFullPath(telLogFolderPath.Value()) : new PathHelper().GetFullPath(KnownStrings.TelemetryLogFolder); var openCommand = new CliCommand { Command = "open", Arguments = folderFullpath }; if (VerboseOption.HasValue()) { Console.WriteLine($"Opening telemetry log folder {folderFullpath}"); } var cmdresult = await openCommand.RunCommand(); if (!string.IsNullOrEmpty(cmdresult.StandardError)) { Console.WriteLine($"Error: {cmdresult.StandardError}"); } }); }
public CompressLogsCommand() : base("CompressLogs", "This will create a .zip of the existing log files. The file will be created by default in the log directory") { // command options var optionLogFolderPath = this.Option( "-l|--logfolderroot <PATH>", $"defines that path to the root folder containg the log files. Default value: '{KnownStrings.VsmacLogsFolderPath}'", CommandOptionType.SingleValue); var optionVersionNumber = Option( "-v|--version <VERSION>", "version number for VSMac [7.0 or 8.0]", CommandOptionType.SingleValue); optionVersionNumber.Validators.Add(new VsmacVersionValidator()); var optionDestFilename = Option( "-f|--filename", "defines the filename of the log file that will be created. Default filename has a timestamp and version.", CommandOptionType.SingleValue); this.OnExecute(() => { string logfolder = optionLogFolderPath.HasValue() ? new PathHelper().GetFullPath(optionLogFolderPath.Value()) : new PathHelper().GetFullPath(KnownStrings.VsmacLogsFolderPath); string version = optionVersionNumber.HasValue() ? optionVersionNumber.Value() : KnownStrings.DefaultVsmacVersion; if (!Directory.Exists(logfolder)) { throw new DirectoryNotFoundException($"log directory not found at {logfolder}"); } string destfilename = optionDestFilename.HasValue() ? optionDestFilename.Value() : $"ide-{version}-log-{DateTime.Now.ToString("yyyy.MM.dd.ss.ff")}.zip"; if (VerboseOption.HasValue()) { Console.WriteLine($@"CompressLogFiles called with folder: '{logfolder}' version: '{version}' filename: '{destfilename}'"); } if (VerboseOption.HasValue()) { Console.WriteLine("Creating zip file now"); } System.IO.Compression.ZipFile.CreateFromDirectory( Path.Combine(logfolder, version), Path.Combine(logfolder, destfilename)); Console.WriteLine($"Zip file created at {Path.Combine(logfolder, destfilename)}"); }); }
public CleanLogsCommand() : base("CleanLogs", "This will clean the log folder") { // command options var optionLogFolderPath = this.Option( "-l|--logfolderroot <PATH>", $"defines that path to the root folder containg the log files. Default value: '{KnownStrings.VsmacLogsFolderPath}'", CommandOptionType.SingleValue); var optionVersionNumber = Option( "-v|--version <VERSION>", "version number for VSMac [7.0 or 8.0]", CommandOptionType.SingleValue); optionVersionNumber.Validators.Add(new VsmacVersionValidator()); this.OnExecute(() => { var logFolderRootPath = optionLogFolderPath.HasValue() ? optionLogFolderPath.Value() : new PathHelper().GetFullPath(KnownStrings.VsmacLogsFolderPath); var versionNumber = optionVersionNumber.HasValue() ? optionVersionNumber.Value() : "8.0"; if (VerboseOption.HasValue()) { Console.WriteLine($"CleanLogFolder called with:\n\tlogFolderRootPath:\t{logFolderRootPath}\n\tversionNumber:\t\t{versionNumber}"); } var logfolderfullpath = Path.GetFullPath(Path.Combine(logFolderRootPath, versionNumber)); var filesToDelete = Directory.GetFiles(logfolderfullpath, "*", SearchOption.TopDirectoryOnly); if (filesToDelete.Length > 0) { if (VerboseOption.HasValue()) { Console.WriteLine("Deleting the following files:"); } foreach (var file in filesToDelete) { if (VerboseOption.HasValue()) { Console.WriteLine($"\t{file}"); } File.Delete(file); } } else { Console.WriteLine($"No files to delete in folder: {logfolderfullpath}"); } }); }
public CleanTelemetryLogsCommand() : base("CleanTelemetryLogs", "removes the telemetry log files") { var optionTelFolderPath = Option("-p|--folderPath", "path to the folder that contains log files that will be deleted", CommandOptionType.SingleValue); this.OnExecute(() => { var telFolderFullPath = optionTelFolderPath.HasValue() ? new PathHelper().GetFullPath(optionTelFolderPath.Value()) : new PathHelper().GetFullPath(KnownStrings.VsmacLogsFolderPath); if (!Directory.Exists(telFolderFullPath)) { Console.WriteLine($"Folder not found at: '{telFolderFullPath}'"); return; } var filesToDelete = Directory.GetFiles(telFolderFullPath, "*", SearchOption.TopDirectoryOnly); if (filesToDelete.Length <= 0) { Console.WriteLine("Folder is empty"); } else { if (VerboseOption.HasValue()) { Console.WriteLine($"Cleaning tel folder at: '{telFolderFullPath}'"); } foreach (var file in filesToDelete) { var fileFullPath = Path.GetFullPath(file); if (VerboseOption.HasValue()) { Console.WriteLine($"Removing file {fileFullPath}"); } File.Delete(fileFullPath); } } }); }