To help get you up to speed on how SmoulderingBeachBallCLI works, please consider the the image below.
The way it works is the console receives input from the end-user. The console parses that input and matches it with a "command-method" in "ConsoleCommands.fs". When the command-method finishes its task, it returns its result to the console. That's the simple version at least.
The reason the project is set-up this way is because I built it with Console.Waterworks (C.W.). I will not go into too much detail here about how C.W. works here. Instead, I will give a basic overview. If you would like a more detailed breakdown, please use the following links:
- Console.Waterworks Repository
- Console.Waterworks Wiki
- Console.Waterworks.Core Repository (This is the .Net Core version.)
- Console.Waterworks.Core Wiki (The .Net Core version operates the same way as the traditional .Net one. So, this wiki is not as comprehensive and mostly serves as a place to set-up the .Net Core version of C.W.)
At a basic level, C.W. is a NuGet package which helps you write command-based console programs. From a distance, C.W. programs look a bit like MVC programs. The basic structure of a C.W. program looks like the image below.
For C.W. to operate as it does, it needs to rely on certain things. They are:
- It controls the input-loop from within
main
. - The is a module called
ConsoleCommands
within the project. ConsoleCommands
must reside in a name-space.- There are functions which are
public
andstatic
within theConsoleCommands
module.
As an aside, I wrote C.W. with C# and without F# in mind. Because of this, some of the code is this (console) project looks a little "off". If you would like to know more about using C.W. in an F# environment, please head over to another repository of mine. Its name is Brittle Fish and it is a tutorial/wiki for F# developers wanting to use C.W. It, also, points out potential pitfalls you might run into when using C.W. with F#. You can find Brittle Fish with the following links:
End of aside.
To keep things simple, I recommend you only work within "Program.fs", "Validation.fs" and "ConsoleCommands.fs". Although, once you understand what is happening in "Program.fs", I cannot foresee you venturing outside the other two. How these files work together is as follows:
- The
main
function in "Program.fs" creates an input-loop at run-time. This allows the end-user to enter commands. - C.W. then parse the input with the command and passes it to the relevant command-method in "ConsoleCommands.fs" when it has finished.
- Because C.W. does not provide context specific checks, the command-method will pass the input to "Validation.fs". In here, the input in validated with tailor made checks.
- If the input is valid,the command-method proceeds and completes its task.
- When completed, the command-method returns a message to the console, via C.W.
It is worth pointing out "Validation.fs", also, provides "helper" functions. This is because the program, as a whole, is not that big/complicated. If the program grows its feature-set and complexity, this file will need refactoring. So, keep this in mind if you decide to work with the source code.