hardis:packagexml:remove
Description
Command Behavior
Removes metadata components from a package.xml file using either another package.xml as a filter or inline metadata type/member specifications.
This command is useful for refining your package.xml manifests by excluding components that are being deleted or are otherwise irrelevant for a specific deployment or retrieval.
There are two ways to specify which items to remove:
- Filter
package.xml(--removepackagexml): Provide a secondpackage.xmlfile (e.g., adestructiveChanges.xml) whose components are removed from the source. Defaults todestructiveChanges.xml. - Inline flags (--metadatatypes / --metadatanames): Specify metadata types and/or member names directly on the command line without needing a filter file.
--metadatatypes: Comma-separated list of metadata type names whose entire content is removed (e.g.ApexClass,CustomObject).--metadatanames: Comma-separated list ofTypeName:MemberNamepairs for granular removal (e.g.ApexClass:MyClass,CustomObject:Account__c). Both flags can be combined.
Additional options:
- Source
package.xml: The mainpackage.xmlfile from which components will be removed (specified by--packagexml). Defaults topackage.xml. - Output File: The path to the new
package.xmlfile that will contain the filtered content (specified by--outputfile). - Removed Only Output: The
--removedonlyflag generates apackage.xmlthat contains only the items that were removed from the sourcepackage.xml.
Technical explanations
The command's technical implementation involves:
- File Parsing: It reads and parses the XML content of the source
package.xmland optionally the filterpackage.xml. - Inline Types Building: When
--metadatatypesor--metadatanamesflags are used, the filter structure is built in memory viabuildInlineRemoveTypeswithout reading a file. - Content Comparison and Filtering: It compares the metadata types and members defined in both sources. Components found in the filter are excluded from the output.
- XML Building: After filtering, it rebuilds the XML structure for the new
package.xmlfile. - File Writing: The newly constructed XML content is then written to the specified output file.
removePackageXmlFilesContentUtility: The core logic for this operation is encapsulated within theremovePackageXmlFilesContentutility function, which handles the parsing, filtering, and writing of thepackage.xmlfiles.
Agent Mode
Supports non-interactive execution with --agent:
sf hardis:packagexml:remove --agent
In agent mode, all interactive prompts are skipped and default values are used.
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| agent | boolean | Run in non-interactive mode for agents and automation | |||
| debug | boolean | debug | |||
| flags-dir | option | undefined | |||
| json | boolean | Format output as json. | |||
| metadatanames -n |
option | Comma-separated list of TypeName:MemberName pairs to remove from the package.xml (e.g. ApexClass:MyClass,CustomObject:Account__c) | |||
| metadatatypes -t |
option | Comma-separated list of metadata type names to fully remove from the package.xml (e.g. ApexClass,CustomObject). All members of each type are removed. | |||
| outputfile -f |
option | package.xml output file | |||
| packagexml -p |
option | package.xml file to reduce | |||
| removedonly -z |
boolean | Use this flag to generate a package.xml with only removed items | |||
| removepackagexml -r |
option | package.xml file to use to filter input package.xml (alternative to --metadatatypes / --metadatanames) | |||
| websocket | option | websocket |
Examples
$ sf hardis packagexml:remove -p package.xml -r destructiveChanges.xml -o my-reduced-package.xml
$ sf hardis packagexml:remove -p package.xml --metadatatypes ApexClass,CustomObject -o my-reduced-package.xml
$ sf hardis packagexml:remove -p package.xml --metadatanames ApexClass:MyClass,CustomObject:Account__c -o my-reduced-package.xml
$ sf hardis packagexml:remove -p package.xml --metadatatypes CustomObject --metadatanames ApexClass:MyClass -o my-reduced-package.xml