refactor: factorise output management#38
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors CLI command output handling by introducing a centralized DiagramOutputWriter helper class. The changes aim to eliminate code duplication and standardize how diagram outputs are written to files or the console across all CLI commands.
Changes:
- Introduced
DiagramOutputWriterclass to centralize file and console output logic - Updated
VisualizeCommand,ErdCommand, andClassDiagramCommandto use the new helper - Registered
DiagramOutputWriterin the DI container and introduced command name constants inProgram.cs
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/ProjGraph.Cli/Infrastructure/DiagramOutputWriter.cs | New helper class that encapsulates diagram output logic including file writing, directory creation, and markdown fence determination |
| src/ProjGraph.Cli/Program.cs | Registers DiagramOutputWriter service and uses constants for command names in examples |
| src/ProjGraph.Cli/Commands/VisualizeCommand.cs | Replaced direct file system usage with DiagramOutputWriter dependency |
| src/ProjGraph.Cli/Commands/ErdCommand.cs | Replaced direct file system usage with DiagramOutputWriter dependency |
| src/ProjGraph.Cli/Commands/ClassDiagramCommand.cs | Replaced direct file system usage with DiagramOutputWriter dependency |
Comments suppressed due to low confidence (1)
src/ProjGraph.Cli/Infrastructure/DiagramOutputWriter.cs:48
- The new implementation changes the behavior for console output (when outputPath is null). The original logic
settings.Output?.EndsWith(".mmd", StringComparison.OrdinalIgnoreCase) is falsereturned false for null inputs (no wrapping), while the new logicoutputPath?.EndsWith(".mmd", StringComparison.OrdinalIgnoreCase) is not truereturns true for null inputs (wrapping). This means console output will now be wrapped in markdown fences when it wasn't before. If this behavior change is intentional, it should be documented in the PR description. If not, the logic should be changed tooutputPath?.EndsWith(".mmd", StringComparison.OrdinalIgnoreCase) is falseto preserve the original behavior.
public static bool ShouldWrapInMarkdownFence(string? outputPath)
{
return outputPath?.EndsWith(".mmd", StringComparison.OrdinalIgnoreCase) is not true;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
2 tasks
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: HandyS11 <62420910+HandyS11@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the CLI commands to centralize diagram output handling and standardize output logic across the codebase. The main improvement is the introduction of the
DiagramOutputWriterhelper, which replaces repeated file and console output logic in each command. This makes the code more maintainable and consistent. The changes also update dependency injection and command constructors to use this new helper.Centralization and standardization of diagram output:
DiagramOutputWriterclass insrc/ProjGraph.Cli/Infrastructure/DiagramOutputWriter.cs, providing reusable methods for writing diagram output to file or console and determining Markdown fence wrapping.ClassDiagramCommand,ErdCommand, andVisualizeCommandto useDiagramOutputWriterinstead of directly handling file and console output. This includes updating constructors and replacing output logic in theirExecuteAsyncmethods. [1] [2] [3] [4] [5] [6]DiagramOutputWriter.ShouldWrapInMarkdownFencefor consistency. [1] [2] [3]Dependency injection and program setup:
DiagramOutputWriteras a singleton service in the DI container and updated command registration inProgram.csto use named constants for command names and examples.Codebase simplification: