2024-12-08 December Adventure 2024: Day 8

December Adventure 2024: Day 8

MyCmd: Call Hierarchy Query

I pushed commit 934df52f64349474cf8ec19fe56d96290eb08451 to update query-call-hierarchy.py to also display the unique immediate callers of a function.

For example, running mycmd project run query-call-hierarchy tmp/shell-log-trace mycmd:command_group.source_file_path_for_directory now produces:

The following unique call stacks were foun
---------
mycmd.discover_command_groups_and_commands -> mycmd:pathname.walk_path -> mycmd:pathname.walk_path_for_directory -> mycmd.discover_command_groups_and_commands_callback -> mycmd:command_group.register_command_group -> mycmd:command_group.source_file_path_for_directory
---------
mycmd.discover_command_groups_and_commands -> mycmd:pathname.walk_path -> mycmd:pathname.walk_path_for_directory -> mycmd:pathname.walk_path_for_directory -> mycmd:pathname.walk_path_for_directory -> mycmd.discover_command_groups_and_commands_callback -> mycmd:command_group.register_command_group -> mycmd:command_grou
p.source_file_path_for_directory
---------
mycmd.discover_command_groups_and_commands -> mycmd:pathname.walk_path -> mycmd:pathname.walk_path_for_directory -> mycmd:pathname.walk_path_for_directory -> mycmd.discover_command_groups_and_commands_callback -> mycmd:command_group.register_command_group -> mycmd:command_group.source_file_path_for_directory
---------
The following unique callers called 'mycmd:command_group.source_file_path_for_directory':
---------
mycmd:command_group.register_command_group

The caveat with this tool is that it will only show the calls that happened during the execution of MyCmd that was traced. In this example, mycmd:command_group.source_file_path_for_directory is actually called from two places:

However, as a optimization mechanism, mycmd:command_group.validate_directory_contains_command_group is not called during the discovery process, as it already guaranteed to be on the MyCmd search path.

MyCmd Cleaning Up the Command Group Code

I made decent progress on implementing the concept of the Command Group Registry that I wrote about yesterday.

I try to make small, incremental steps. I’ve got into a pretty good rhythm of making a change, running mycmd project run all (which does linting, formatting, and executing tests) and then making a commit:

I think this was a good start for cleaning up my code. As an easier look at the changes I made today, see this commit comparison.

Next Steps

Tomorrow, I will make similar changes for mycmd-command-lib, which implements the Command data structure. After I finish that, I want to look more closely at things to see if it makes sense to move the Command Group Registry and Command Registry into their own files, along with the discovery functions that are in mycmd-lib.


All of my December Adventure 2024 posts will be linked from here.