Building Interactive Command Line Interfaces in Python
DineshKumar (~dineshkumarkb) |
I am sure as a pythonista you would have used/developed command line interfaces in your career. What is one thing you hate about the clis? I think I heard what you said. That's right. Remember every single command of operation. This becomes even more difficult as the cli grows.
What's the best solution we have for this?
We copy the most frequently used commands in a notepad and copy/paste them. Voila. Done.
A better solution:
Recently I was given a task of refactoring our cli. I was thinking what can we do better to a cli that's just working perfectly fine(ignoring the performance issues) to attract more users. I happened to read an article in the Python Weekly about
PyInquirer. So, why not leverage this to refactor the cli.
PyInquirer basically works with a JSON which prompts a number of questions to a user, the user inputs are captured and returned as answers. The questions can be made contextual and stored as user inputs based on the selection. This was something which I leveraged and built an interactive cli which looked visually attractive and also overcomes the cons of a regular cli.
I am Dinesh Kumar with 11 years of experience in software development. I have been building back-end cloud applications with Python, command line interface applications that interact with cloud and on prem APIs, SDKs for video analytics.
Medium : https://dineshkumarkb.medium.com/
StackOverflow : https://stackoverflow.com/users/5907578/dineshkumar