Skip to content

Commit 1c9a163

Browse files
committed
feat: command to add packages
1 parent 45da345 commit 1c9a163

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

internal/add/add.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package add
2+
3+
import (
4+
"log/slog"
5+
"os"
6+
"path/filepath"
7+
8+
"pault.ag/go/debian/deb"
9+
)
10+
11+
type CLI struct {
12+
Source string `required:"" help:"Path to packages to add" type:"existingdir"`
13+
Repo string `required:"" help:"Path to repository directory" type:"existingdir"`
14+
}
15+
16+
func (c *CLI) Run() error {
17+
return filepath.Walk(c.Source, func(path string, info os.FileInfo, err error) error {
18+
if err != nil {
19+
return err
20+
}
21+
if info.IsDir() {
22+
return nil
23+
}
24+
if filepath.Ext(path) != ".deb" {
25+
return nil
26+
}
27+
28+
slog.Info("Scanning package", "path", path)
29+
deb, cl, err := deb.LoadFile(path)
30+
if err != nil {
31+
return err
32+
}
33+
defer cl()
34+
35+
newPath := filepath.Join(c.Repo, "binary-"+deb.Control.Architecture.String(), filepath.Base(path))
36+
slog.Info("Adding package", "path", newPath)
37+
if err := os.MkdirAll(filepath.Dir(newPath), 0o700); err != nil {
38+
return err
39+
}
40+
if err := os.Link(path, newPath); err != nil {
41+
return err
42+
}
43+
return nil
44+
})
45+
}

internal/publish/publish.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
)
77

88
type CLI struct {
9-
Dists string `arg:"" required:"" help:"Path to dists directory" type:"existingdir"`
10-
Keyring string `required:"" help:"Path to GPG keyring" type:"existingfile"`
11-
KeepVersions int `help:"Number of versions to keep" default:"2"`
9+
Dists string `arg:"" required:"" help:"Path to dists directory" type:"existingdir" env:"EZAPT_DISTS"`
10+
Keyring string `required:"" help:"Path to GPG keyring" type:"existingfile" env:"EZAPT_KEYRING"`
11+
KeepVersions int `help:"Number of versions to keep" default:"2" env:"EZAPT_KEEP_VERSIONS"`
1212
}
1313

1414
func (c *CLI) Run() error {

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import (
44
"log/slog"
55

66
"github.com/alecthomas/kong"
7+
"kastelo.dev/ezapt/internal/add"
78
"kastelo.dev/ezapt/internal/publish"
89
)
910

1011
type CLI struct {
1112
Publish publish.CLI `cmd:"" help:"Publish packages to a repository."`
13+
Add add.CLI `cmd:"" help:"Add packages to a repository."`
1214
}
1315

1416
func main() {

0 commit comments

Comments
 (0)