8 Writing Command Methods
Craig Oates edited this page 4 years ago

If you are unsure what a command-method is, please read the following page:

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

  1. Command-methods must be static.
  2. Every command-method must return a string.
  3. The ConsoleCommands class must be public and static.
  4. Every command-method-method must reside in the ConsoleCommands class.

The reason why every command-method must return a string is because Console.Waterworks.Core (C.W.C.) needs to provide feedback to the end-user. With that said, you are free to write to the console whenever you want. On top of that, you can return an empty string if you want. C.W.C. does not care what is in the string as long as it is a string.

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

public static string CommandMethodName()
    // Your code goes here...
    return "The result/message you want to feedback to the end-user."

More examples can be found at the following link:

What is important to note here is the importance of the command-method names. The names you use are the exact same commands your end-user will enter at run-time. The console's input is, also, case-sensitive. This means you can have two command-methods called Test and test and have them do different things.

screenshot of command-method and console commands

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

screenshot of error-handling 1

screenshot of error-handling 2

To be clear, there are limits to the amount of types you can use with your command-methods. For a full, list of all the coercion types, please refer to the Coercion Types List in the main Console.Waterworks wiki. The link for it is as follows:

If you write command-methods 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-methods.