IBM / lmctl

Cloud Pak for Network Automation (CP4NA) (previously ALM/TNCO) command line tool
Apache License 2.0
4 stars 19 forks source link

Internal CLI refactoring to improve efficiency of adding new commands #148

Closed dvaccarosenna closed 2 years ago

dvaccarosenna commented 2 years ago

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:

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.

dvaccarosenna commented 2 years ago

Refactoring from multiple demos/PoCs bought in