-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving DX, adding a --ci option and listing generated reports in output #68
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package Cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/halleck45/ast-metrics/src/Analyzer" | ||
"github.com/halleck45/ast-metrics/src/Configuration" | ||
pb "github.com/halleck45/ast-metrics/src/NodeType" | ||
"github.com/halleck45/ast-metrics/src/Report" | ||
) | ||
|
||
type ScreenEnd struct { | ||
isInteractive bool | ||
files []*pb.File | ||
projectAggregated Analyzer.ProjectAggregated | ||
// program | ||
tea *tea.Program | ||
// reports | ||
configuration Configuration.Configuration | ||
reports []Report.GeneratedReport | ||
} | ||
|
||
func NewScreenEnd( | ||
isInteractive bool, | ||
files []*pb.File, | ||
projectAggregated Analyzer.ProjectAggregated, | ||
configuration Configuration.Configuration, | ||
reports []Report.GeneratedReport, | ||
) *ScreenEnd { | ||
return &ScreenEnd{ | ||
isInteractive: isInteractive, | ||
files: files, | ||
projectAggregated: projectAggregated, | ||
configuration: configuration, | ||
reports: reports, | ||
} | ||
} | ||
|
||
type modelEnd struct { | ||
} | ||
|
||
func (m modelEnd) Init() tea.Cmd { | ||
return nil | ||
} | ||
|
||
func (m *modelEnd) Reset(files []*pb.File, projectAggregated Analyzer.ProjectAggregated) { | ||
} | ||
|
||
func (m modelEnd) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
return m, nil | ||
} | ||
|
||
func (m modelEnd) View() string { | ||
return "" | ||
} | ||
|
||
func (r *ScreenEnd) Render() { | ||
// List reports | ||
if r.configuration.Reports.HasReports() { | ||
|
||
fmt.Println("\n📁 These reports have been generated:") | ||
|
||
for _, report := range r.reports { | ||
fmt.Println("\n ✔ " + report.Path + " (" + report.Type + ")") | ||
fmt.Println("\n " + report.Description) | ||
} | ||
|
||
fmt.Println("") | ||
} | ||
|
||
// Tips if configuration file does not exist | ||
if !r.configuration.IsComingFromConfigFile { | ||
fmt.Println("\n💡 We noticed that you haven't yet created a configuration file. You can create a .ast-metrics.yaml configuration file by running: ast-metrics init") | ||
fmt.Println("") | ||
} | ||
|
||
fmt.Println("\n🌟 If you like AST Metrics, please consider starring the project on GitHub: https://github.com/Halleck45/ast-metrics/. Thanks!") | ||
fmt.Println("") | ||
|
||
} | ||
|
||
func (r *ScreenEnd) Reset(files []*pb.File, projectAggregated Analyzer.ProjectAggregated) { | ||
} | ||
|
||
func (r ScreenEnd) GetModel() tea.Model { | ||
return modelEnd{} | ||
} | ||
|
||
func (r ScreenEnd) GetScreenName() string { | ||
return "End" | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,49 @@ | ||
package Cli | ||
|
||
import ( | ||
"testing" | ||
"testing" | ||
|
||
"github.com/halleck45/ast-metrics/src/Analyzer" | ||
pb "github.com/halleck45/ast-metrics/src/NodeType" | ||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/halleck45/ast-metrics/src/Analyzer" | ||
pb "github.com/halleck45/ast-metrics/src/NodeType" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewScreenHome(t *testing.T) { | ||
isInteractive := true | ||
files := []*pb.File{} | ||
projectAggregated := Analyzer.ProjectAggregated{} | ||
isInteractive := true | ||
files := []*pb.File{} | ||
projectAggregated := Analyzer.ProjectAggregated{} | ||
|
||
screenHome := NewScreenHome(isInteractive, files, projectAggregated) | ||
screenHome := NewScreenHome(isInteractive, files, projectAggregated) | ||
|
||
if screenHome.isInteractive != isInteractive { | ||
t.Errorf("Expected isInteractive to be %v, but got %v", isInteractive, screenHome.isInteractive) | ||
} | ||
if screenHome.isInteractive != isInteractive { | ||
t.Errorf("Expected isInteractive to be %v, but got %v", isInteractive, screenHome.isInteractive) | ||
} | ||
|
||
if len(screenHome.files) != len(files) { | ||
t.Errorf("Expected files to be %v, but got %v", files, screenHome.files) | ||
} | ||
if len(screenHome.files) != len(files) { | ||
t.Errorf("Expected files to be %v, but got %v", files, screenHome.files) | ||
} | ||
} | ||
|
||
func TestGetModel(t *testing.T) { | ||
isInteractive := true | ||
files := []*pb.File{} | ||
projectAggregated := Analyzer.ProjectAggregated{} | ||
isInteractive := true | ||
files := []*pb.File{} | ||
projectAggregated := Analyzer.ProjectAggregated{} | ||
|
||
screenHome := NewScreenHome(isInteractive, files, projectAggregated) | ||
model := screenHome.GetModel() | ||
screenHome := NewScreenHome(isInteractive, files, projectAggregated) | ||
model := screenHome.GetModel() | ||
|
||
if len(model.files) != len(files) { | ||
t.Errorf("Expected files to be %v, but got %v", files, model.files) | ||
} | ||
// sending the "enter" key | ||
model, _ = model.Update(tea.KeyMsg{Type: tea.KeyEnter}) | ||
_, ok := model.(modelScreenSummary) | ||
assert.True(t, ok) | ||
} | ||
|
||
func TestInit(t *testing.T) { | ||
model := modelChoices{} | ||
cmd := model.Init() | ||
model := modelChoices{} | ||
cmd := model.Init() | ||
|
||
if cmd != nil { | ||
t.Errorf("Expected cmd to be nil, but got %v", cmd) | ||
} | ||
} | ||
if cmd != nil { | ||
t.Errorf("Expected cmd to be nil, but got %v", cmd) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Now I have enough context to provide the final response:
The modelEnd implementation is necessary but can be improved
The
modelEnd
struct is a required implementation as it's used byScreenEnd
to satisfy theScreen
interface contract, which requires aGetModel()
method returning atea.Model
. However, its current empty implementation could be enhanced:View()
method should return a meaningful message or confirmation of completionReset()
method should handle cleanup if needed🔗 Analysis chain
Verify the necessity of the modelEnd implementation.
The
modelEnd
struct appears to be a placeholder implementation of the tea.Model interface. If it's not actively used, consider removing it to reduce unnecessary complexity. If it's intended for future use, please add TODO comments explaining the planned functionality.Let me search for more context about where this model is being used.
Let me check if there's any interface or contract that requires this tea.Model implementation.
Let me check one of the other screen implementations to understand the pattern better.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 412
Script:
Length of output: 4312
Script:
Length of output: 2133
Script:
Length of output: 7224