Improve CyberPanel CLI Usability and Version Handling #1069
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While orchestrating CyberPanel with Ansible, I decided to leverage the cyberpanel-cli. While I have the programming knowledge to understand the functionalities of the cli and how to invoke them, the user-friendliness of the CLI was lacking in certain areas (for example, no info was provided about which functions the user could call). The code changes in this pull request have therefore focused on improving user-friendliness in the following areas:
Added a new method
getAllowedFunctions()
to the cliParser class that maintains a static list of available functions. These functions are grouped into categories such as "Website Management", "DNS Management", "Backup Management" and more. This list is used to validate the function argument provided by the user and to print the list of available functions if an unknown function is provided.Improved the error handling when an unknown function is provided as argument to the cli. Now it not only prints the help message from ArgumentParser, but also indicates that the function is unknown and prints a neatly formatted list of available functions.
Additionally, I've corrected the version output, as it was not working correctly:
I've updated the
get_cyberpanel_version
function to handle non-JSON data. Previously, it could only interpret JSON formatted data from version.txt and would fail if the data was provided as plain text lines (which is the case after a new installation). The function now attempts to interpret the data as JSON first and if that fails, it tries to interpret the data as plain text lines. This allows for greater flexibility in the format of the data in version.txt, making the function more robust to changes in the way version information is stored.The proposed changes aim to make the CyberPanel CLI more user-friendly, especially for users who aren't familiar with the underlying code or Python programming. I hope these changes are helpful and I welcome any feedback.