Open anselor opened 4 years ago
Can you give some guidelines on how one can "assess" an example. I definitely would like to jump in on one or two examples and rewrite them. Not sure where to start though.
First check if the example matches the current API. We are usually pretty good about updating examples when APIs change, but I wouldn't be surprised if some examples are broken.
Then determine if you think the example is self-explanatory to a newcomer. This is subjective, but if you think you can make an example more clear, feel free to submit it.
@jayrod One of the things is we have examples that span a range of API changes over time.
We have some that are somewhat redundant in that they are copies/tweaks of another example. In these cases, it may make more sense to combine into a single example with lots of comments explaining the different things being demonstrated.
We probably also have some that are no longer representative of how we would recommend developers implement something based on the latest API improvements.
For example, today we would probably recommend you register/unregister CommandSets instead of manually hiding/showing commands.
@anselor
For example, today we would probably recommend you register/unregister CommandSets instead of manually hiding/showing commands.
That's an interesting thing to bring up and could make for a good example. The CLI I work on is a good case for using CommandSets
alongside enabling/disabling commands. The CommandSet
feature allows me to easily place command functions and their respective resources in their own files. But my CLI has two modes, and in one mode a whole category of these commands aren't available. I could register/unregister their CommandSets
each time a user switches modes. However, using the enabling/disabling command feature allows me to provide a custom message if a user tries to run a command which doesn't exist in the current mode.
So instead of it saying, "foo is not a recognized command, alias, or macro" a user is shown something like "foo is only available when in bar mode". Now they know to switch to the proper mode instead of being confused as to why a command no longer exists.
There are certainly other cases, like uninstalling a plugin, where I would want to unregister a CommandSet
instead of just disabling commands.
@kmvanbrunt
First check if the example matches the current API.
Soo.... how would I figure out which examples you speak of ;)
@jayrod I used Pycharm to inspect the code in the examples directory. It found an "Unresolved reference" error in colors.py that I just fixed.
Doesn't look like there are any other API errors.
We've made a lot of significant improvements in recent releases but some of our examples are still lagging behind a lot. There are cases where the examples no longer represent the easiest/cleanest solution or what we currently consider to be best practices when using cmd2.
examples
directory to help walk people through what's here. Identify which example to start with, and then group/describe the other examplesdecorator_example.py
first_app.py
andhello_cmd2.py
decorator_example.py
arg_decorators.py
anddecorator_example.py
decorator_example.py
hello_cmd2.py
first_app.py
* swap
getattr(args, 'func')
forargs.cmd2_handler.get()