Skip to content

Conversation

@anselor
Copy link
Contributor

@anselor anselor commented Jul 24, 2020

ok, this should be the real one we want.

Going back to being integrated into the cmd2 core instead of a plugin.
Removed support for arbitrary functions as loadable modular commands. Modular commands must be in a CommandSet.
Added additional documentation and examples.

Closes #943

@anselor anselor requested review from kmvanbrunt and tleonhardt July 24, 2020 17:22
@anselor anselor requested a review from kotfu as a code owner July 24, 2020 17:22
@anselor anselor force-pushed the modular_commands branch 3 times, most recently from c9a8f49 to a92faa5 Compare July 24, 2020 18:59
@codecov
Copy link

codecov bot commented Jul 24, 2020

Codecov Report

Merging #961 into master will increase coverage by 0.09%.
The diff coverage is 98.98%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #961      +/-   ##
==========================================
+ Coverage   97.74%   97.83%   +0.09%     
==========================================
  Files          21       22       +1     
  Lines        4217     4487     +270     
==========================================
+ Hits         4122     4390     +268     
- Misses         95       97       +2     
Impacted Files Coverage Δ
cmd2/argparse_custom.py 94.09% <94.11%> (-0.08%) ⬇️
cmd2/decorators.py 99.21% <98.11%> (-0.79%) ⬇️
cmd2/cmd2.py 97.15% <99.42%> (+0.25%) ⬆️
cmd2/__init__.py 100.00% <100.00%> (ø)
cmd2/argparse_completer.py 100.00% <100.00%> (ø)
cmd2/command_definition.py 100.00% <100.00%> (ø)
cmd2/constants.py 100.00% <100.00%> (ø)
cmd2/exceptions.py 100.00% <100.00%> (ø)
plugins/ext_test/cmd2_ext_test/cmd2_ext_test.py 91.30% <100.00%> (ø)
plugins/template/cmd2_myplugin/__init__.py 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 787c952...b932ad4. Read the comment docs.

@anselor anselor force-pushed the modular_commands branch 5 times, most recently from 6fdd73a to 6837065 Compare July 27, 2020 21:25
terminators: Optional[List[str]] = None, shortcuts: Optional[Dict[str, str]] = None) -> None:
terminators: Optional[List[str]] = None, shortcuts: Optional[Dict[str, str]] = None,
command_sets: Optional[Iterable[CommandSet]] = None,
auto_load_commands: bool = True) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this set to True? Won't that needlessly run _autoload_commands() for a lot of projects which don't need to call it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do because, for projects that choose to use CommandSets they will 'just work'. The search for child classes is fast because it's asking Python for child classes that have already been loaded. This should just be a lookup of information that's already loaded in memory.

@anselor anselor force-pushed the modular_commands branch from 21397c8 to 4cb15ee Compare July 30, 2020 05:14
Copy link
Member

@tleonhardt tleonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to update CHANGELOG before merging in

anselor and others added 12 commits August 3, 2020 18:17
Issue #943

New class CommandSet can be used to tag a class as a command class. If
the constructor is simple, the object will automatically be instantiated
and loaded.
New register_command decorator to tag any arbitrary function as a
command.
…oad. Added unit tests. Moved installing commands into separate functions that can be called

Issue #943
…ding command functions

Adds handling of some edge cases. More thorough test coverage.
anselor and others added 18 commits August 3, 2020 18:17
register arbitrary functions as commands.
Added example that demonstrates use of each of the command decorators
with CommandSets.
Adds unit test that verifies that CommandSets containing decorators load
and process commands correctly.
Updated the constructor declaration for Cmd2ArgumentParser to explicitly
re-declare argparse constructor parameters.
Added additional documentation
load/unload.
Updated examples and documentation to include discussion of injectable
sub-commands.
sub-commande => subcommand
Added help/aliases to `as_subcommand_to` decorator.
Change setup.cfg so that pytest only runs tests in the tests directory by default.

Attempting to run tests in the isolated_tests directory was causing a crash
through to the ArgparseCompleter if one is registered.
For subcommands, the registered argparse instance for the subcommand is now tagged with the
CommandSet from which it originated.
If a CommandSet is detected, it's now passed in as 'self' for the
completion functions.
Fixes some issue found with removing a subcommand.
Adds additional tests.
Added a check to prevent removal of a CommandSet if it has commands with sub-commands
from another CommandSet bound to it.
Documentation improvements.
Standardized around using CommandSetRegistrationException during commandset install/uninstall related errors.
Added support for nested sub-command injection.
…efore passing to command handlers to access sub-command handlers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow modular command definition

4 participants