Currently the implementation of many CLI commands make use of the TNCOTarget class, which provides some common behaviour. However there are still multiple lines of repeated code in each child class, particularly around validating the value of options to work out whether an ID or name will be used to identify an object in TNCO (CP4NA) to interact with.
It's currently very time consuming to add new commands with the TNCOTarget.
In various PoCs there has been some work to refactor TNCOTarget, to provide common behaviour through decorators and subclasses of the click Command class instead. This allows each command to be written as a "normal click command" and then apply the behaviours required depending on the action.
Some common behaviours we have refactored into a decorator include:
Determine the option(s) to be used to identify an object on a get/update/delete (or other) command. This is useful when an object can be referred to by ID or name or any other combination of attributes
Support a --set option for setting attributes of an object (also existed in TNCOTarget)
Support a -f option to allow a JSON or YAML file copy of an object to be provided (also existed in TNCOTarget)
Ability to merge --set and -f values together to produce one version of the object, which was previously unsupported
The above reduces the number of lines of code required to give commands a common look and feel to the user, for every type of supported object.
Currently the implementation of many CLI commands make use of the
TNCOTarget
class, which provides some common behaviour. However there are still multiple lines of repeated code in each child class, particularly around validating the value of options to work out whether an ID or name will be used to identify an object in TNCO (CP4NA) to interact with.It's currently very time consuming to add new commands with the
TNCOTarget
.In various PoCs there has been some work to refactor
TNCOTarget
, to provide common behaviour through decorators and subclasses of the clickCommand
class instead. This allows each command to be written as a "normal click command" and then apply the behaviours required depending on the action.Some common behaviours we have refactored into a decorator include:
--set
option for setting attributes of an object (also existed in TNCOTarget)-f
option to allow a JSON or YAML file copy of an object to be provided (also existed in TNCOTarget)--set
and-f
values together to produce one version of the object, which was previously unsupportedThe above reduces the number of lines of code required to give commands a common look and feel to the user, for every type of supported object.