Taking refactoring to new heights
You may have been wondering why we didn’t extract options and handler methods into their own code artifacts (such as classes).
The reason is that options and handler methods (and also arguments) are usually unique to a specific command. For this reason, they are defined in the command class.
However, in situations where they would need to be used by more than one command, we would have extracted them into their own code artifact. This reasoning is important to keep in mind in order to avoid over-complexifying our design by over-abstracting it.
In the case of an option, we would have created a dedicated class. Here’s an example of outputfileOption
we used in our ExportCommand
class:
using System.CommandLine; namespace bookmarkr.Options; public class FileInfoOption : Option<FileInfo> { public FileInfoOption(string[] aliases, string? description = null, bool onlyAllowLegalFileNames...