3 The CLI's Flow
Craig Oates edited this page 4 years ago

To help get you up to speed on how SmoulderingBeachBallCLI works, please consider the the image below.

smoulderingbeachballcli general flow

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:

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.

console.waterworks flow

For C.W. to operate as it does, it needs to rely on certain things. They are:

  1. It controls the input-loop from within main.
  2. The is a module called ConsoleCommands within the project.
  3. ConsoleCommands must reside in a name-space.
  4. There are functions which are public and static within the ConsoleCommands 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:

  1. The main function in "Program.fs" creates an input-loop at run-time. This allows the end-user to enter commands.
  2. C.W. then parse the input with the command and passes it to the relevant command-method in "ConsoleCommands.fs" when it has finished.
  3. 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.
  4. If the input is valid,the command-method proceeds and completes its task.
  5. 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.

smoulderingbeachballcli file flow