1 Writing Command Methods in F#
Craig Oates edited this page 4 years ago

If you are unsure what a command-method is, please read Overview of Command-Methods before continuing.

When it comes to writing command-methods, there are certain requirements you must meet. They are:

  1. Each command-method must be static.
  2. Each command must return a string.

To be frank, the first point exists because of the characteristics of C#. For the most part, you will not need to deal with the "static" aspect. This is because an F# module doubles-up as a static class -- from Console.Waterworks (C.W.) perspective. Thus, every function in ConsoleCommands is already static. It is not immediately clear, that's all.

The reason each command-method must return a string is because C.W. needs to provide feedback to the end-user. With that said, you are still free to write to the console whenever you want. On top of that, you can return an empty string if you prefer that. C.W. does not care what is inside the string, as long as it is a string.

Having taken the above into account, here is what a typical command-method looks like:

let test () =
	// Your business logic would go here.
	"C.W.  is set-up and ready to go."

More examples can be found at the following links:

What is important to note here is the command-methods name. This is what the end-user must enter at run-time to execute said command-method. The input is, also, case-sensitive. So, if you wanted to, you could use test and Test as seperate command-methods.

command-method mirroring run-time commands

case sensitive command-methods

Another feature of C.W. is it parses and coerces input arguments. This means your command-methods can include arguments. C.W. takes care of the error handling and messaging too.

run-time error handling

To be clear, there are limits to the amount of types you can use with you command-methods. For a full list of all the coercion types, please refer to the Coercion Types List in the main C.W. wiki.

If you write a command-method with arguments not on the coercion list, you will get a run-time error. With that said, you are free to use whatever types you want inside the command-method.