HaveIBeenPwned / EmailAddressExtractor

A project to rapidly extract all email addresses from any files in a given path
BSD 3-Clause "New" or "Revised" License
64 stars 23 forks source link

Configuration Changes #62

Closed GStefanowich closed 1 year ago

GStefanowich commented 1 year ago

Refactored the CommandLineProcessor to spit out a Config class that holds the contents of any CLI inputs. Config uses reflection to make implementing various options a lot easier, instead of just continuing on the existing switch statement now that there are a lot more options.

The current growing switch:

https://github.com/HaveIBeenPwned/EmailAddressExtractor/blob/6e638a199e5fb46e5ab42782b1fe4995c476750e/src/CommandLineProcessor.cs#L68-L107


Since config options are now picked up with reflection, the --help/-h/-? option now automatically updates, as it was missing a lot of options for awhile until f63e4b6

The -o and -r options are now simply as follows:

/// <summary>The path to write collected <see cref="EmailAddress"/>es to</summary>
[CommandLineOption("o", "output", Description = "File path to write output file", Expects = "path")]
public string OutputFilePath { get; private set; } = Defaults.OUTPUT_FILE_PATH;

/// <summary>The path to write the summary report to</summary>
[CommandLineOption("r", "report", Description = "File path to write report file", Expects = "path")]
public string ReportFilePath { get; private set; } = Defaults.REPORT_FILE_PATH;

--help will now output:

Syntax: AddressExtractor -?
Syntax: AddressExtractor -v
Syntax: AddressExtractor <input [input...]> [-o output] [-r report]

  input                 One or more input file paths
  --debug               Enables debug mode, prints timings and exceptions
  -?, -h, --help        Help for the command line arguments
  -o, --output <path>   File path to write output file
  -q, --quiet           Runs in quiet mode, not as verbose
  --recursive           Recursively enters directories provided to search for files
  -r, --report <path>   File path to write report file
  --skip-exceptions     Skips any continue prompts on exceptions
  --threads <#>         Specifies the number of Tasks to use for parsing Regex
  -v, --version         Prints the application version
  -y, --yes             Skips any normal continue prompts

Fixed #59

I've now added a separate option for prompts on exceptions: --skip-exceptions

/// <summary>If the prompt to Continue on Exceptions should be skipped</summary>
[CommandLineOption("skip-exceptions", Description = "Skips any continue prompts on exceptions")]
public bool SkipExceptions { get; private set; } = Defaults.SKIP_EXCEPTIONS;

I also slightly refactored Email Filters and File Readers to be able to be passed the Config, so if they need to be configured in any way its now doable. Previously both of these things were constructed staticly. Now they've been moved into a Runtime class


It was suggested in #61 to be able to control whether rfc3696 is handled or not. I've not done anything to implement it here but if it's something you think is doable without creating too many issues, being able to check in Filters what the config mode is is now possible.

Creating a config option for this is now also very easy:

enum Mode
{
    NONE,
    RFC3696
}

[CommandLineOption("mode", Description = "Specify a mode of operation")]
public Mode Mode { get; private set; } = Mode.NONE;

This would enable something like --mode rfc3696