Skip to content

Commit 352587f

Browse files
authored
Merge pull request #8 from HyDE-Project/aur/ready
2 parents ccc2629 + 51c415b commit 352587f

File tree

11 files changed

+150
-236
lines changed

11 files changed

+150
-236
lines changed

.github/.goreleaser.yaml

Lines changed: 0 additions & 67 deletions
This file was deleted.

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/release.yml

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,34 @@
11
name: Go Release
22

33
on:
4-
push:
5-
tags:
6-
- "v*"
7-
branches:
8-
- master
4+
push:
5+
tags:
6+
- "v*"
97

108
permissions:
11-
contents: write
12-
packages: write
13-
issues: write
9+
contents: write
10+
packages: write
11+
issues: write
1412

1513
jobs:
16-
goreleaser:
17-
runs-on: ubuntu-latest
18-
steps:
19-
- name: Checkout
20-
uses: actions/checkout@v4
21-
with:
22-
fetch-depth: 0
14+
goreleaser:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
2321

24-
- name: Set up Go
25-
uses: useblacksmith/setup-go@v6
26-
with:
27-
go-version: "1.24.1"
22+
- name: Set up Go
23+
uses: actions/setup-go@v4
24+
with:
25+
go-version: "1.24.1"
2826

29-
- name: Run GoReleaser (tag)
30-
if: startsWith(github.ref, 'refs/tags/v')
31-
uses: goreleaser/goreleaser-action@v5
32-
with:
33-
distribution: goreleaser
34-
version: v2.11.0
35-
args: release --clean --config .github/.goreleaser.yaml
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38-
39-
- name: Upload hydectl binary artifact
40-
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
41-
uses: actions/upload-artifact@v4
42-
with:
43-
name: hydectl-binaries
44-
path: dist/hydectl*
45-
46-
- name: Run GoReleaser (master)
47-
if: github.ref == 'refs/heads/master'
48-
uses: goreleaser/goreleaser-action@v5
49-
with:
50-
distribution: goreleaser
51-
version: v2.11.0
52-
args: release --clean --config .github/.goreleaser.yaml
53-
env:
54-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
- name: Run GoReleaser
28+
uses: goreleaser/goreleaser-action@v5
29+
with:
30+
distribution: goreleaser
31+
version: latest
32+
args: release --clean
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
hydectl

.goreleaser.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
project_name: hydectl
2+
3+
before:
4+
hooks:
5+
- go mod tidy
6+
7+
builds:
8+
- env:
9+
- CGO_ENABLED=0
10+
goos:
11+
- linux
12+
goarch:
13+
- amd64
14+
- arm64
15+
- "386"
16+
main: ./main.go
17+
binary: "hydectl-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
18+
ldflags:
19+
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
20+
21+
archives:
22+
- format: tar.gz
23+
name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}"
24+
files:
25+
- LICENSE
26+
- README.md
27+
28+
checksum:
29+
name_template: "checksums.txt"
30+
31+
snapshot:
32+
name_template: "{{ incpatch .Version }}-next"
33+
34+
changelog:
35+
sort: asc
36+
filters:
37+
exclude:
38+
- "^docs:"
39+
- "^test:"
40+
- "^ci:"
41+
- "^chore:"
42+
43+
release:
44+
github:
45+
owner: HyDE-Project
46+
name: hydectl
47+
prerelease: auto
48+
draft: false

cmd/dispatch.go

Lines changed: 12 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ package cmd
55
import (
66
"encoding/json"
77
"fmt"
8-
"os"
98
"os/exec"
10-
"path/filepath"
119

1210
"hydectl/internal/logger"
1311
"hydectl/internal/plugin"
@@ -26,16 +24,16 @@ var dispatchCmd = &cobra.Command{
2624
Short: "Dispatch a plugin command",
2725
Long: `Dispatch a plugin command by specifying the plugin name and arguments.`,
2826
Run: func(cmd *cobra.Command, args []string) {
29-
if listPlugins {
30-
scripts, err := plugin.LoadScripts(ScriptPaths)
31-
if err != nil {
32-
logger.Errorf("Error loading scripts: %v", err)
33-
fmt.Printf("Error loading scripts: %v\n", err)
34-
return
35-
}
27+
scripts, err := plugin.FindAllScripts(ScriptPaths)
28+
if err != nil {
29+
logger.Errorf("Error loading scripts: %v", err)
30+
fmt.Printf("Error loading scripts: %v\n", err)
31+
return
32+
}
3633

34+
if listPlugins {
3735
fmt.Println("Available Plugins:")
38-
for _, script := range scripts {
36+
for script := range scripts {
3937
fmt.Println(script)
4038
}
4139
return
@@ -49,35 +47,8 @@ var dispatchCmd = &cobra.Command{
4947
pluginName := args[0]
5048
pluginArgs := args[1:]
5149

52-
// Filter out non-existent directories
53-
existingScriptPaths := filterExistingPaths(ScriptPaths)
54-
55-
var scriptPath string
56-
for _, dir := range existingScriptPaths {
57-
path := filepath.Join(dir, pluginName)
58-
if _, err := os.Stat(path); err == nil {
59-
scriptPath = path
60-
break
61-
}
62-
}
63-
64-
if scriptPath == "" {
65-
// Try to find the script with a known extension
66-
for _, dir := range existingScriptPaths {
67-
for _, ext := range []string{".sh", ".py"} {
68-
path := filepath.Join(dir, pluginName+ext)
69-
if _, err := os.Stat(path); err == nil {
70-
scriptPath = path
71-
break
72-
}
73-
}
74-
if scriptPath != "" {
75-
break
76-
}
77-
}
78-
}
79-
80-
if scriptPath == "" {
50+
scriptPath, ok := scripts[pluginName]
51+
if !ok {
8152
logger.Infof("Plugin %s does not exist.", pluginName)
8253
fmt.Printf("Plugin %s does not exist.\n", pluginName)
8354
return
@@ -90,18 +61,6 @@ var dispatchCmd = &cobra.Command{
9061
},
9162
}
9263

93-
func filterExistingPaths(paths []string) []string {
94-
var existingPaths []string
95-
for _, path := range paths {
96-
if _, err := os.Stat(path); err == nil {
97-
existingPaths = append(existingPaths, path)
98-
} else {
99-
logger.Debugf("Directory does not exist: %s", path)
100-
}
101-
}
102-
return existingPaths
103-
}
104-
10564
var dynamicCommands []*cobra.Command
10665

10766
func init() {
@@ -161,20 +120,14 @@ type ScriptUsage struct {
161120
// Example function to dynamically add plugin commands
162121
func AddPluginCommands() {
163122
logger.Debug("Loading scripts for dynamic commands")
164-
scripts, err := plugin.LoadScripts(ScriptPaths)
123+
scripts, err := plugin.FindAllScripts(ScriptPaths)
165124
if err != nil {
166125
logger.Errorf("Error loading scripts: %v", err)
167126
return
168127
}
169128

170-
for _, script := range scripts {
129+
for script, scriptPath := range scripts {
171130
logger.Debugf("Processing script: %s", script)
172-
scriptPath := findScriptPath(script)
173-
if scriptPath == "" {
174-
logger.Infof("Plugin %s does not exist.", script)
175-
continue
176-
}
177-
178131
usage, err := getScriptUsage(scriptPath)
179132
if err != nil {
180133
logger.Errorf("Error getting usage for script %s: %v", script, err)
@@ -228,20 +181,3 @@ func getScriptUsage(scriptPath string) (*ScriptUsage, error) {
228181

229182
return &usage, nil
230183
}
231-
232-
func findScriptPath(pluginName string) string {
233-
existingScriptPaths := filterExistingPaths(ScriptPaths)
234-
for _, dir := range existingScriptPaths {
235-
path := filepath.Join(dir, pluginName)
236-
if _, err := os.Stat(path); err == nil {
237-
return path
238-
}
239-
for _, ext := range []string{".sh", ".py"} {
240-
path := filepath.Join(dir, pluginName+ext)
241-
if _, err := os.Stat(path); err == nil {
242-
return path
243-
}
244-
}
245-
}
246-
return ""
247-
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/charmbracelet/bubbletea v1.3.5
1313
github.com/charmbracelet/lipgloss v1.1.0
1414
github.com/charmbracelet/log v0.4.1
15-
github.com/muesli/reflow v0.3.0
1615
github.com/spf13/cobra v1.5.0
1716
github.com/spf13/pflag v1.0.5
1817
github.com/thiagokokada/hyprland-go v0.4.0

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,16 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
4545
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
4646
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
4747
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
48-
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
4948
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
5049
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
5150
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
5251
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
5352
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
5453
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
55-
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
56-
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
5754
github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=
5855
github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=
5956
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6057
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
61-
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
6258
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
6359
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
6460
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=

0 commit comments

Comments
 (0)