7
The Help Attributes
Craig Oates edited this page 4 years ago
To use the "Help Section" feature, you will need to know about the four attributes it is built with. They are as follows,
- ListCommand: When you attach this attribute to a command-method, that method will appear in the help section at run-time. You can, also, pass in
false
, as a parameter. This explicit declaration means the method will not appear at run-time. I use this option to turn things on an off without needing to rewrite the whole line every time. It helps with reducing temporary comment code, as well. - Parameters: You can use this attribute to list out the parameters the end-user will need to pass into the command-method. The reason why you need to pass in a
string
to the attributes constructor is so you have flexibility. Some methods have parameter lists which are large and difficult to read. Because of this, it is in your end-user's interest for you to simplify it. I admit I could have programmed Console.Waterworks to figure it out for you. But, that would have taken that decision away from you. Whilst it is not perfect, I believe the string approach is the most practical solution. - Describe: This attribute allows you to offer contextual information to the end-user. To use it, you pass in a
string
to the attribute's constructor. - Usage: To help your end-users even more, you can provide them with an example of how to use your command-methods. To use this attribute, pass in a
string
to its constructor.
To you get a sense of how they look in practice, please use the links below:
- ConsoleCommands.cs (part of CW-Console)
- Wet Pancakes' ConsoleCommands.cs (this uses Console.Waterworks in a slightly more advance manner)
- Smouldering Beach Ball's ConsoleCommands.fs (this uses the attributes with F#)
You will only see these attributes decorating command-methods found in each project's "ConsoleCommands.cs" file (or ConsoleCommands.fs" file if you're using F#).
// Copy and paste this in to ConsoleCommands file to speed up the typing.
[ListCommand()] // Passing in no parameters defaults to true.
[Description("")]
[Parameters("")]
[Usage("> ")]