-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regarding KISS and direction of the project #1251
Comments
Agreed that I'd love to see the functionality of cmd2 (and similar tools!) split into separate libraries. I think there's a case to be made for figuring out how to disentangle (a) command discovery and argument completion, (b) a bunch of default/example commands, and (c) the REPL. For my project, I've looked at rich, click, typer, prompt_toolkit, among others. They all make assumptions at a fairly deep level about how they'll do input/output that make them very difficult to embed or reuse in other contexts. click and typer especially are amazing at command discovery and autocompletion but make foundational assumptions that they'll be parsing the command-line args of a program. |
I am in favor of taking a dependency on rich and replacing most of Incorporating On the other hand, @kmvanbrunt @anselor @kotfu Do any of you have strong opinions one way or another? FYI, this is somewhat a duplicate of #1216 |
I broadly agree with @GnikDroy's original sentiment. We've always wanted cmd2 to have "batteries included", but we also have to draw the line somewhere or we'll end up with emacs. The current state of
My preference would be to not include any text formatting capabilities in cmd2. Instead of If we were to go in that direction, it would mean something like:
If there is enough interest in exploring this, I'll be happy to create a branch and start working on it so we can at least see how it might work out. |
As I recall, our table creator was added because it was needed for many of the tab completion formatting. I was unable to comment earlier but much of what @kotfu suggests is similar to what I was thinking. Instead I'd propose that we have a defined output generation interface for the various forms of formatted output cmd2 internally depends on. We could have a progressive enhancement approach where adapters to libraries like |
Just to clarify a bit. I am not advocating to replace the internal stuff with What I'm advocating for is to remove them from the public API. Take table creation for instance. Cmd2's table creation API is exposed to the user (mentioned in the docs, methods are not private etc). So, that means every user has the option to choose between a dedicated library for these kinds of stuff like The user has to compare the pros/cons of I don't think exposing table creation is a great idea. Cmd2 doesn't promise to help you render output of commands. That is the responsibility of libraries like rich. Additional rendering stuff that is exposed to the user: Is it really necessary to expose this to users? Personally, I think helping users render output of commands is not cmd2's responsibility. Rich is a library tailored to do exactly this. |
I think the key difficulty here is that it rapidly starts to become impossible to disentangle the core of cmd2 from output rendering - consider the example up at the top! Presumably we all still want "core cmd2" to automatically produce command help, as well as do things like command- and argument-completion, and produce/update a prompt – but all of that implies deep dependencies on the output rendering. At some point, we'd find ourselves re-coding all of cmd2's output into a markup format that can then be processed by an output library and rendered appropriately (and then needing to write some kind of standard lowest-common-denominator output rendering for cmd2 to fall back on). We might then wonder whether it wouldn't just be easier to depend on a single library that does the terminal-appropriate rendering already, given markup input. Completion and prompt also have that problem, although possibly worse, since it's actually interactive. |
As @kotfu noted above, this project has strived to be a 'batteries-included' solution to building a command shell. As such, some form of output rendering will always be provided. Any of the formatting functionality we've implemented we've opted to expose so smaller projects can use it if they choose to. I know of projects that use the built-in output formatting because it's easy and good enough for basic needs. I do think that making it easier to override the output formatting to leverage each project's text rendering library of choice is a worthy goal moving forward. That being said, being mindful of feature/scope creep is also a good idea. The last thing we want is for us to become a bloated mess of a project from ever-increasing scope. I'll note that the py and ipy commands have been a part of cmd2 for many years - predating many of the newer enhancements that make it easier to modularize commands. It probably makes sense for us to transition many of the built-in commands into CommandSets that are pre-loaded in the default case for now and eventually transition them to be only loaded if explicitly requested. |
@GnikDroy, is the source code for your highlighted help message available online? I'd like to see how you did it and see if I could integrate something similar into |
@kotfu https://gist.github.com/GnikDroy/e6d74bef43871935df08cf6de979e680 COLOR_SCHEME = {
"info": "yellow",
"warn": "red",
"success": "green",
"list": "cyan",
"banner": "red"
} randomize_arg_color=Truerandomize_arg_color = FalseSee original image. |
I've done several experiments to see how to use I tried using regular expressions to highlight the output: couldn't reliably highlight all the parts of the help I wanted. I tried feeding highlighted arguments to I tried subclassing Then I found what I think is the best answer, and best of all, someone already did the work: the rich_argparse module provides a |
@kotfu I made a number of customizations to how arguments are grouped to make them clearer. I imagine what would make sense is to make the same customizations of the rich powered HelpFormatter and then swap out which we use by default depending on whether rich is present. |
Worth noting that It might still be worth it to do this though. |
Firstly, thank you for your excellent piece of software. cmd2 works well for my applications.
A case for KISS
I realize that it is rather unusual to request for the removal of a feature, but I think some of the features of cmd2 don't fit. A very clear example is the table creation API. As you already know, Textualize/rich is a project that also supports this, is popular, and is likely used in conjunction with cmd2. Please correct me if I'm wrong, but cmd2 isn't supposed to be a library to help render output of a command. But facilitate writing commands that can be used in a shell like environment.
Features like, autocomplete, history, argument processing, scripting, aliases fit well with the project. Features like table creation do not. I think table creation should be removed from cmd2 and delegated to a project like rich.
Similarly, the main
Cmd2
class also has some features that might be better off separated into a plugin.For example,
And all the relevant codepaths are better off in a separate plugin/mixin instead of the main Cmd2 class.
Maybe some stuff in
ansi.py
is also better off delegated to rich, or some other library? I am not sure.A case for improvement.
A feature that is in scope for the project and potentially useful to the users is syntax highlighted help messages and argument options. Many people, including me, have been using this for quite some time, and I believe it should be the default (but customizable) behavior.
Example:
The text was updated successfully, but these errors were encountered: