private static Watcher CreateWatcherWithOptions(Options options) { var watcher = new Watcher(); watcher.DirectoryPath = options.DirectoryPath ?? Environment.CurrentDirectory; watcher.Filter = options.Filter ?? "*.log"; watcher.LineWriter = CreateWriter(options); return watcher; }
private static ILineWriter CreateWriter(Options options) { var writer = new ConsoleLineWriter(); if (options.EnableColorSchema) { EnableColorSchema(writer, options); } else { writer.AutoDetectColorSchema = false; } return writer; }
private static Options CreateOptions(CommandLineParameters parameters) { var options = new Options(); options.HelpWanted = parameters.DetachNamedBool("?"); if (options.HelpWanted) { return options; } options.DirectoryPath = parameters.DetachPositional(); options.Filter = parameters.DetachNamed("f"); options.EnableColorSchema = !parameters.DetachNamedBool("nc"); options.ColorSchemaName = parameters.DetachNamed("c"); if (!options.EnableColorSchema && !string.IsNullOrEmpty(options.ColorSchemaName)) { throw new ArgumentException("Options nc and c are incompatible with each other"); } return options; }
private static void EnableColorSchema(ConsoleLineWriter writer, Options options) { var colorSchemas = LoadColorSchemas(); if (colorSchemas == null) { throw new ApplicationException("No color schema file found"); } if (options.ColorSchemaName == null) { writer.AutoDetectColorSchema = true; writer.ColorSchemas = colorSchemas; } else { writer.AutoDetectColorSchema = false; writer.ColorSchema = colorSchemas.Find(cs => cs.Name == options.ColorSchemaName); if (writer.ColorSchema == null) { throw new ApplicationException(string.Format("Color schema {0} was not found.", options.ColorSchemaName)); } } }