Skip to content

feat: implement 'locate' command for resource-to-module mapping#1081

Open
AshokThangavel wants to merge 6 commits intointersystems:mainfrom
AshokThangavel:feat/locate-command
Open

feat: implement 'locate' command for resource-to-module mapping#1081
AshokThangavel wants to merge 6 commits intointersystems:mainfrom
AshokThangavel:feat/locate-command

Conversation

@AshokThangavel
Copy link
Contributor

Add locate command to identify resource owner modules

Description

This PR introduces the locate command (alias loc) to the IPM shell. It allows developers to quickly identify which module "owns" a specific resource (Class, Routine, Include file, etc.). The locate command provides a native CLI wrapper around the existing FindHomeModule logic to get the owning module and its current version in a format consistent with the list command.

fixes: #1073

Key Features

  • Alias Support: Supports both locate and the shorthand loc.
  • Resource Versatility: Works with .cls, .inc, .mac, and other registered resource types.
  • Consistent UI: Output matches the standard ZPM list format: <ModuleName> <Version>.
  • Robust Error Handling: Validates required arguments and provides clear feedback if a resource is unmapped.

Unit Test

A new test suite TestLocateCommand was added to verify the command's behavior across different scenarios.

Unit Test Results:

zpm:USER>loc %IPM.Main.cls

zpm 0.10.6-SNAPSHOT
zpm:USER>loc %IPM.Main.cls

zpm 0.10.6-SNAPSHOT
zpm:USER>loc Testify.Home.cls

testify 1.0.2
zpm:USER>loc Test.Main.cls
Resource 'Test.Main.cls' is not currently mapped to an installed module.
zpm:USER>
  • Success: loc %IPM.Common.inc returns the correct module.
  • Success: locate %IPM.Main.cls returns the correct module.
  • Resilience: Gracefully handles non-existent resources.
  • Validation: Correctly catches missing arguments via shell validation.

- Added 'locate' (alias 'loc') to identify the owning module of a resource.
- Uses %IPM.ExtensionBase.Utils:GetHomeModuleName for reliable lookup.
- Formatted output to match 'list' command (Name + Version).
- Added unit tests for various resource types (.cls, .inc).
- Validated handling of various resource types (.inc, .cls).
- Confirmed graceful error handling for missing arguments and non-existent resources.
Copy link
Collaborator

@isc-kiyer isc-kiyer left a comment

Choose a reason for hiding this comment

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

@AshokThangavel Thanks for contributing this! Just a few small notes


<command name="locate" aliases="loc">
<description>Find the module that owns a specific resource.</description>
<parameter name="resource" description="resource: The full name of the resource (e.g., My.Class.cls, Utils.inc)." />
Copy link
Collaborator

Choose a reason for hiding this comment

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

The parameter should be marked required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I've updated the parameter as required.

ClassMethod Locate(ByRef CommandInfo)
{
set resource = $get(CommandInfo("parameters","resource"))
if resource="" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This won't be needed once the parameter is marked required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the condition as well

<example description="Show details of history item with ID 3 and information for each undergone lifecyle phase">history details 3 -phases</example>
</command>

<command name="locate" aliases="loc">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I would call this locate-resource with no alias since locate is a bit ambiguous and seems to overlap with search

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I've updated the command from locate to locate-resource

}
set moduleName = ##class(%IPM.ExtensionBase.Utils).GetHomeModuleName(resource)
if (moduleName="") {
write $$$FormattedLine($$$Red, "Resource '"_ resource_"' is not currently mapped to an installed module.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I would replace "mapped to" as "part of" since mappings are an overloaded term at the IRIS level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed the message string!

* **Rename** `locate` command to `locate-resource` and **remove alias** per maintainer feedback to avoid ambiguity with system commands.
* **Update** error message to use "part of" instead of "mapped to" to avoid confusion with InterSystems IRIS mapping terminology.
Method TestLocateCommand()
{
do $$$LogMessage("Testing 'loc' alias with .inc resource")
set status = ..RunCommand("loc %IPM.Common.inc")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe all these commands will need to be changed to locate-resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the unit test code. Thank you!

CHANGELOG.md Outdated

### Added
- #1024: Added flag -export-python-deps to publish command
- #1081: implement locate command for resource-to-module mapping
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: capitalize "implement" and move to 0.10.7

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to 1.10.7 release. Thank you!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like you need to pull from main to resolve the conflict here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pulled from main and resolved the conflicts as well. Thank you!

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.

Add locate command

3 participants