7 CLI Validation Overview
Craig Oates edited this page 4 years ago

This is the third of the main three files you will work -- within this (CLI) project. At this moment in time, "Validation.fs" provides too many features. It handles the validation logic, as the name implies, and houses all the "helper" functions. Because the program is rather small, it seemed like overkill to fragment the code too much. So, for now, the "helper" functions will remain in "Validation.fs". If the project's feature-set grows, this file will need refactoring. Until then, the code will stay as it is.

The type of validation this file provides is complimentary to what Console.Waterworks (C.W.) provides. To help explain, consider the following:

A command-method takes a string which indicates a save-path. C.W. checks the input type is a string and "Validate.fs" makes sure the path is valid/accessible.

The reason why is because C.W. does the type checking automatically. So, it seems foolish not to use it.

If you would like to know more about how C.W. performs its validation checks, please use the following links:

Instead of copying and pasting the code from "Validation.fs" into this page, I recommend reading the actual file yourself. You can view it using the following link:

As you work your way through the file, try keeping the relationship between "Validation.fs" and "ConsoleCommands.fs" in mind. Everything in "Validation.fs" aids "ConsoleCommands.fs" and nothing else.

As a general rule, "Validation.fs" consists of three "sections". They are as follows:

  1. Creating an "image specification" (E.G. BrushSpec)
  2. Parsing string-based input (colours, paths, Etc.)
  3. Creating a "stringly-typed" colour list/system

It is worth pointing out two and three reflect the nature of console programs (I.E. text based). Also, I limited the colourList and skiaColourList as a way to keep things simple. The console does not provide a way for the end-user to look at the colour before confirming it. And, people tend to find remembering "blue" a lot easier than #068BEC. Having said that, the main (NuGet) library, allows you to specify your colours using RGB values. So, you can do that if/when you hook it up to a GUI if you want.

If you have not viewed the code in "Validation.fs", here a quick look at the available colours users can use with the C.L.I.:

// Code in Validation.fs.
// This is for the System.Drawing colours.
let colourList =
    ["blue", Brushes.AliceBlue
     "brown", Brushes.Brown
     "black", Brushes.Black
     "gray", Brushes.Gray
     "green", Brushes.Green
     "purple", Brushes.Purple
     "red", Brushes.Red
     "white", Brushes.White
     "yellow", Brushes.Yellow ]
    |> Map.ofList
		 
// This is for the SkiaSharp colours.
let skiaColourList =
    ["blue", SKColors.AliceBlue
     "brown", SKColors.Brown
     "black", SKColors.Black
     "gray", SKColors.Gray
     "grey", SKColors.Gray
     "green", SKColors.Green
     "purple", SKColors.Purple
     "red", SKColors.Red
     "white", SKColors.White
     "yellow", SKColors.Yellow ]
    |> Map.ofList