private static string ReportOrTerse(Checker checker, CheckFlags flags) { if (flags.Terse) { return($"{(checker.Passed ? "Pass" : "Fail")}\t{checker.Errors.Count} errors {checker.Warnings.Count} warnings\t{Ellipsis(checker.Filename, 60)}"); } else { return(checker.Report()); } }
private static int CheckFolderCommand(string target, string destination, CheckFlags flags) { var rtz = Directory.EnumerateFiles(target, "*.rtz", SearchOption.AllDirectories); var rtzp = Directory.EnumerateFiles(target, "*.rtzp", SearchOption.AllDirectories); var combined = rtz.Concat(rtzp); if (!combined.Any()) { Console.WriteLine($"No files to check in {target}"); return(3); } int result = 0; var sb = new StringBuilder(); sb.AppendLine($"{DateTime.UtcNow.ToString("G")}"); sb.AppendLine(); foreach (string filename in combined) { var checker = new Checker(filename, flags.RouteNameOnlyWarning); if (flags.ErrorsOnly && checker.Passed) { continue; } string report = ReportOrTerse(checker, flags); if (!string.IsNullOrEmpty(destination)) { Console.WriteLine($"Checked {filename}"); sb.AppendLine(report); } else { Console.WriteLine(report); } if (!checker.Passed) { result = 2; } } if (!string.IsNullOrEmpty(destination)) { File.WriteAllText(destination, sb.ToString()); Console.WriteLine($"Wrote report to {destination}"); } return(result); }
static int SafeMain(string[] args) { CheckFlags flags = InitCheckFlags(args); args = RemoveSwitches(args); if (args.Length < 2) { return(Usage()); } string target = args[1]; // 2nd param always a file string destination = args.Length >= 3 ? args[2] : string.Empty; if (IsCommand(args, "zip")) { if (!File.Exists(target)) { return(FileNotFound(target)); } Zipper.Zip(target, destination); } else if (IsCommand(args, "unzip")) { if (!File.Exists(target)) { return(FileNotFound(target)); } UnzipCommand(target, destination); } else if (IsCommand(args, "check")) { if (Directory.Exists(target)) { return(CheckFolderCommand(target, destination, flags)); } if (!File.Exists(target)) { return(FileNotFound(target)); } return(CheckCommand(target, destination, flags)); } else { return(Usage()); } return(0); }
private static int CheckCommand(string target, string destination, CheckFlags flags) { var checker = new Checker(target, flags.RouteNameOnlyWarning); string report = ReportOrTerse(checker, flags); if (!string.IsNullOrEmpty(destination)) { Console.WriteLine($"Writing report to {destination}"); File.WriteAllText(destination, report); } else { Console.WriteLine(report); } return(checker.Passed ? 0 : 2); }