Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions .github/workflows/DependencyUpdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ on:
default: 'update-dependencies'
type: string

# Add explicit permissions
# Update permissions to allow PR creation
permissions:
contents: write # Required for pushing changes
pull-requests: write # Optional, but useful if you want to create PRs instead of direct pushes
contents: write
pull-requests: write
checks: write
statuses: write

jobs:
update-deps:
Expand All @@ -28,11 +30,20 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'schedule' && 'main' || github.ref }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '>=1.21'
go-version: '1.21.8' # Use a specific stable version

- name: Debug Go environment
run: |
go version
go env
go list -m all

- name: Update dependencies
run: |
Expand All @@ -44,10 +55,12 @@ jobs:
go mod tidy

- name: Run go vet
run: go vet ./...
run: |
go vet -v ./...

- name: Run tests
run: go test -v ./...
run: |
go test -v ./...

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
Expand All @@ -70,7 +83,7 @@ jobs:

Please review the changes and ensure all tests pass in your environment.
branch: ${{ github.event.inputs.branch_name }}-${{ github.run_id }}
base: main
base: ${{ github.event_name == 'schedule' && 'main' || github.ref_name }}
labels: |
dependencies
automated pr
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/MustacheCase/zanadir
go 1.24

require (
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.10.0
gopkg.in/yaml.v3 v3.0.1
Expand All @@ -12,9 +11,7 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
)
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
Expand Down
49 changes: 24 additions & 25 deletions output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ package output
import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/MustacheCase/zanadir/config"
"github.com/MustacheCase/zanadir/suggester"
"github.com/olekukonko/tablewriter"
)

// Updated interface: single Response method with a response type parameter.
// Output interface defines the contract for output services
type Output interface {
Response(suggestions []*suggester.CategorySuggestion, responseType string) error
}

type service struct{}

// wrapText wraps text to a specified width
func wrapText(text string, lineWidth int) string {
words := strings.Fields(text)
if len(words) == 0 {
Expand All @@ -44,32 +43,31 @@ func wrapText(text string, lineWidth int) string {
return strings.Join(lines, "\n")
}

func (s *service) Response(suggestions []*suggester.CategorySuggestion, responseType string) error {
if responseType == config.OutputTable {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Category", "Description", "Suggested Tools"})
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")
table.SetColumnSeparator("|")
table.SetRowSeparator("-")
table.SetRowLine(true)
table.SetAutoWrapText(true)
table.SetReflowDuringAutoWrap(true)
// printTable prints suggestions in a formatted table
func printTable(suggestions []*suggester.CategorySuggestion) {
// Print header
fmt.Println("Category | Description | Suggested Tools")
fmt.Println("---------|-------------|----------------")

for _, suggestion := range suggestions {
toolNames := []string{}
for _, tool := range suggestion.Suggestions {
toolNames = append(toolNames, tool.Name)
}
tools := strings.Join(toolNames, ", ")
for _, suggestion := range suggestions {
toolNames := []string{}
for _, tool := range suggestion.Suggestions {
toolNames = append(toolNames, tool.Name)
}
tools := strings.Join(toolNames, ", ")

// Wrap description for better display
description := wrapText(suggestion.Description, 60)
// Wrap description for better display
description := wrapText(suggestion.Description, 60)

table.Append([]string{suggestion.Name, description, tools})
}
// Print row
fmt.Printf("%s | %s | %s\n", suggestion.Name, description, tools)
}
}

table.Render()
// Response handles the output of suggestions in the specified format
func (s *service) Response(suggestions []*suggester.CategorySuggestion, responseType string) error {
if responseType == config.OutputTable {
printTable(suggestions)
return nil
}

Expand All @@ -81,6 +79,7 @@ func (s *service) Response(suggestions []*suggester.CategorySuggestion, response
return nil
}

// NewOutputService creates a new output service instance
func NewOutputService() Output {
return &service{}
}
Loading