Skip to content

Migrate command-line tools from CommandLineParser to System.CommandLine#259

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-255
Draft

Migrate command-line tools from CommandLineParser to System.CommandLine#259
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-255

Conversation

Copy link
Copy Markdown

Copilot AI commented Aug 29, 2025

This PR migrates all command-line tools in the repository from the third-party CommandLineParser library to Microsoft's official System.CommandLine library (currently in preview), as requested in the issue.

Changes Made

Package Updates

  • FHIR Tools: Updated both R4 and Stu3 CommandLineTool projects to use System.CommandLine v2.0.0-beta4.22272.1
  • DICOM Tool: Updated CommandLineTool project to use System.CommandLine v2.0.0-beta4.22272.1
  • Removed all references to CommandLineParser (versions 2.8.0-2.9.1)

Code Migration

  • FHIR Shared Code: Completely rewrote Microsoft.Health.Fhir.Anonymizer.Shared.CommandLineTool/Program.cs to use System.CommandLine's modern API with proper option definitions and handlers
  • DICOM Tool: Migrated AnonymizerCliTool.cs and simplified AnonymizerOptions.cs to work with System.CommandLine's approach
  • Command-Line Interface: Maintained full backward compatibility - all existing options and behaviors preserved

Enhanced Features

  • Better Help Output: System.CommandLine provides cleaner, more consistent help formatting
  • Improved Error Handling: Enhanced validation and error messages using System.CommandLine's built-in features
  • Modern API: Leverages System.CommandLine's contemporary parsing patterns and type safety

Validation

All command-line tools have been thoroughly tested:

  • FHIR R4 Anonymizer: Successfully processed 13 sample FHIR R4 files
  • FHIR Stu3 Anonymizer: Successfully processed 11 sample FHIR Stu3 files
  • DICOM Anonymizer: Successfully processed sample DICOM files in both single-file and folder modes
  • Unit Tests: All existing DICOM command-line unit tests continue to pass (12/12)
  • Help Output: Verified clean help formatting for all tools

Example Usage

The command-line interface remains unchanged for users:

# FHIR R4 (unchanged)
./Microsoft.Health.Fhir.Anonymizer.R4.CommandLineTool -i input_folder -o output_folder -v

# DICOM (unchanged) 
./Microsoft.Health.Dicom.Anonymizer.CommandLineTool -I input_folder -O output_folder

But now with improved help output:

Usage:
  Microsoft.Health.Fhir.Anonymizer.R4.CommandLineTool [options]

Options:
  -i, --inputFolder <inputFolder> (REQUIRED)    Folder to locate input resource files.
  -o, --outputFolder <outputFolder> (REQUIRED)  Folder to save anonymized resource files.
  -v, --verbose                                 Provide additional details in processing.
  --help                                        Show help and usage information

This migration positions the project to use Microsoft's official command-line parsing library while maintaining full compatibility with existing usage patterns.

Fixes #255.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…lementations complete

Co-authored-by: chrisribe <1999791+chrisribe@users.noreply.github.com>
Copilot AI changed the title [WIP] Use System.CommandLine Migrate command-line tools from CommandLineParser to System.CommandLine Aug 29, 2025
Copilot AI requested a review from chrisribe August 29, 2025 19:24
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.

Use System.CommandLine

2 participants