public void Parse(string timeSpanDescription, TimeSpan?expectedTimeSpan) { if (expectedTimeSpan is null) { Assert.Throws <FormatException>(() => FriendlyTimeSpan.Parse(timeSpanDescription)); } else { Assert.Equal(expectedTimeSpan, FriendlyTimeSpan.Parse(timeSpanDescription)); } }
static int Main(string[] args) { FriendlyTimeSpan.RegisterTypeConverter(); ReflectionCommand.ProgramName = "latham"; ReflectionCommand.UsageLine = (command, fullCommandName) => { var usageLine = $"usage: {ReflectionCommand.ProgramName} [GLOBAL OPTIONS] "; if (command is ProjectCommand) { usageLine += "-p PROJECT_FILE "; } return(usageLine + $"{fullCommandName} [OPTIONS]"); }; string?logFilePath = null; int consoleVerbosity = (int)LogEventLevel.Fatal - (int)LogEventLevel.Information; int logFileVerbosity = (int)LogEventLevel.Fatal - (int)LogEventLevel.Debug; void UpdateLogging() { LogEventLevel GetLevel(int verbosity) { var min = (int)LogEventLevel.Verbose; var max = (int)LogEventLevel.Fatal; verbosity = max - Math.Min(max, Math.Max(verbosity, min)); return((LogEventLevel)verbosity); } var loggerConfiguration = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console(restrictedToMinimumLevel: GetLevel(consoleVerbosity)); if (logFilePath is string) { loggerConfiguration = loggerConfiguration .WriteTo .File( logFilePath, rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: GetLevel(logFileVerbosity)); } Log.Logger = loggerConfiguration.CreateLogger(); } UpdateLogging(); var commandSet = new CommandSet(ReflectionCommand.ProgramName) { { $"usage: {ReflectionCommand.ProgramName} [GLOBAL OPTIONS] COMMAND [COMMAND OPTIONS]" },