5 Extending Clon

As you know, Clon already provides seven built-in option types: flags and six other types for valued options (see Built-In Valued Options). After using Clon for a while, you may find that however brilliant and perfectly designed it is, none of the provided built-in types fullfill your requirements exactly. There are two ways around this: the right way and the wrong way (hint).

The wrong, although perhaps quicker way would be to use the stropt option type to simply retrieve unprocessed string values, and then do whatever tweaking required on them. In doing so, you risk reinventing some of Clon’s wheels.

The right way is to define a new option type. Properly defined option types are a good thing because they allow for reusability and also extensibility, since new option types can always be defined on top of others. In this chapter we explain how to extend Clon by providing new option types. We illustrate the process with the example of the built-in enum one.

Oh, and I almost forgot. I hope it is obvious to everyone that new option types are always valued. There’s no point in extending Clon with options that don’t take any arguments, since we already have flags.