master
Craig Oates 4 years ago
parent
commit
3e8c2a2f87
  1. 37
      Writing-Command-Methods-in-F%23.md

37
Writing-Command-Methods-in-F%23.md

@ -0,0 +1,37 @@
If you are unsure what a command-method is, please read [**Overview of Command-Methods**](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:
```f#
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:
- [BrittleFish Console Project (.Net)](https://git.abbether.net/craig.oates/Brittle-Fish/src/branch/master/BrittleFish/ConsoleCommands.fs)
- [BrittleFish.Core Console Project (.Net Core)](https://git.abbether.net/craig.oates/Brittle-Fish/src/branch/master/BrittleFishCore/ConsoleCommands.fs)
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](command-method-mirroring.png)
![case sensitive command-methods](case-sensitive-command-methods.png)
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](run-time-error-handling.png)
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**](https://git.abbether.net/craig.oates/Console.Waterworks/wiki/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.
Loading…
Cancel
Save