Skip to content

feat: refactor flag for displaying scratch images#684

Merged
patrickhoefler merged 1 commit intomainfrom
feat/scratch-flag
Jul 13, 2025
Merged

feat: refactor flag for displaying scratch images#684
patrickhoefler merged 1 commit intomainfrom
feat/scratch-flag

Conversation

@patrickhoefler
Copy link
Copy Markdown
Owner

This pull request introduces a new --scratch flag to replace the --separate-scratch flag, enhancing the flexibility of handling scratch images in Dockerfile visualizations. It also updates related documentation and tests to reflect these changes. Additionally, improvements were made to testing guidelines and test coverage.

Core Feature Update: Scratch Image Handling

  • Replaced the --separate-scratch flag with the --scratch flag, which supports three modes: collapsed, hidden, and separated for handling scratch images (README.md, internal/cmd/root.go, internal/dockerfile2dot/convert.go). [1] [2] [3]
  • Updated the logic in dockerfileToSimplifiedDockerfile and related helper functions to handle the three modes of the --scratch flag, including skipping scratch images in hidden mode and generating unique IDs for separated mode (internal/dockerfile2dot/convert.go). [1] [2]

Testing Enhancements

  • Added comprehensive test cases to validate the behavior of the new --scratch flag in all three modes (collapsed, hidden, separated) and edge cases like invalid modes (internal/cmd/root_test.go, internal/dockerfile2dot/convert_test.go). [1] [2]
  • Removed outdated test cases for the deprecated --separate-scratch flag and added cleanup logic for output files in tests (internal/cmd/root_test.go).

Documentation Updates

  • Updated the README.md to document the new --scratch flag and its modes (README.md).
  • Improved testing guidelines in .github/copilot-instructions.md to emphasize comprehensive test coverage, including edge cases and error conditions (.github/copilot-instructions.md).

Code Quality Improvements

  • Refactored the dockerfileToSimplifiedDockerfile function by introducing helper functions (processFromInstruction, processCopyInstruction, etc.) for better maintainability and readability (internal/dockerfile2dot/convert.go).

These changes collectively improve the flexibility of scratch image handling, enhance test coverage, and maintain high code quality.

Copilot AI review requested due to automatic review settings July 13, 2025 13:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors Dockerfile scratch image handling by replacing the old boolean flag with a new three‐mode --scratch enum, updates parsing logic and helper functions accordingly, and refreshes documentation and tests to cover all modes.

  • Replace --separate-scratch bool flag with --scratch enum (collapsed, hidden, separated) in CLI, loader, and converter
  • Refactor dockerfileToSimplifiedDockerfile into smaller helper functions and update addExternalImages for multi-mode scratch handling
  • Enhance tests for all scratch modes, remove deprecated tests, and update documentation and testing guidelines

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/dockerfile2dot/load.go Change loader signature to accept scratchMode
internal/dockerfile2dot/convert.go Refactor scratch logic into helper functions
internal/dockerfile2dot/convert_test.go Add tests for collapsed, hidden, and separated modes
internal/dockerfile2dot/load_test.go Update loader tests to use default collapsed mode
internal/cmd/root.go Remove old flag, register new enum-based --scratch
internal/cmd/root_test.go Update CLI tests for the new scratch flag
README.md Document the new --scratch flag and its modes
.github/copilot-instructions.md Expand testing guidelines including edge cases and make check
Comments suppressed due to low confidence (4)

internal/cmd/root.go:28

  • Replacing the --separate-scratch flag with --scratch is a breaking change for CLI consumers; please add a deprecation notice or migration guide in the CHANGELOG or documentation.
	scratchFlag        enum

.github/copilot-instructions.md:24

  • This guideline assumes a make check target exists; please verify that your Makefile or CI configuration defines this target or update the instructions accordingly.
- Always use `make check` for efficient linting and testing - it runs golangci-lint, tests with coverage, and enforces code quality standards in one command

internal/cmd/root_test.go:495

  • [nitpick] The test names mix phrases like 'collapsed mode' and 'hidden mode'; consider standardizing the format (e.g., scratch flag: <mode>) to make each case clearer.
			name:    "scratch flag collapsed mode",

@patrickhoefler patrickhoefler merged commit 6c2a1f1 into main Jul 13, 2025
8 checks passed
@patrickhoefler patrickhoefler deleted the feat/scratch-flag branch July 13, 2025 14:06
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.

2 participants