Skip to content
This repository was archived by the owner on Feb 4, 2026. It is now read-only.

Commit 64dc7bf

Browse files
committed
feat: install packages from lockfile
1 parent add7a3d commit 64dc7bf

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

cmd/help.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var commandsHelp = map[string]string{
1717
"help": "Display help",
1818
"info": "Display package information",
1919
"init": "Create a local repository",
20-
"install": "Install a package",
20+
"install": "Install packages",
2121
"list": "List installed packages",
2222
"uninstall": "Uninstall a package",
2323
"update": "Update installed packages",

cmd/install.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,46 @@ package cmd
22

33
import (
44
"errors"
5+
"fmt"
56

67
"github.com/nalgeon/sqlpkg-cli/internal/spec"
78
)
89

9-
const installHelp = "usage: sqlpkg install package"
10+
const installHelp = "usage: sqlpkg install [package]"
11+
12+
// InstallAll installs all packages from the lockfile.
13+
func InstallAll(args []string) error {
14+
lck, err := readLockfile()
15+
if err != nil {
16+
return err
17+
}
18+
debug("loaded the lockfile with %d packages", len(lck.Packages))
19+
20+
if len(lck.Packages) == 0 {
21+
log("no packages found in the lockfile")
22+
return nil
23+
}
24+
25+
errCount := 0
26+
for _, pkg := range lck.Packages {
27+
path := pkg.Specfile
28+
if path == "" {
29+
debug("missing specfile for %s, falling back to name/owner", pkg.FullName())
30+
path = pkg.FullName()
31+
}
32+
err = installPackage(path)
33+
if err != nil {
34+
errCount += 1
35+
log("! %s", err)
36+
}
37+
}
38+
39+
if errCount > 0 {
40+
return fmt.Errorf("failed to install %d packages", errCount)
41+
}
42+
log("installed %d packages", len(lck.Packages))
43+
return nil
44+
}
1045

1146
// Install installs a new package or updates an existing one.
1247
func Install(args []string) error {
@@ -15,6 +50,12 @@ func Install(args []string) error {
1550
}
1651

1752
path := args[0]
53+
err := installPackage(path)
54+
return err
55+
}
56+
57+
// installPackage installs a package using a specfile from a given path.
58+
func installPackage(path string) error {
1859
log("> installing %s...", path)
1960

2061
pkg, err := readSpec(path)

main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ func execCommand() error {
2626
case "init":
2727
return cmd.Init(args)
2828
case "install":
29+
if len(args) == 0 {
30+
return cmd.InstallAll(args)
31+
}
2932
return cmd.Install(args)
3033
case "uninstall":
3134
return cmd.Uninstall(args)
3235
case "update":
33-
if len(args) == 1 {
34-
return cmd.Update(args)
36+
if len(args) == 0 {
37+
return cmd.UpdateAll(args)
3538
}
36-
return cmd.UpdateAll(args)
39+
return cmd.Update(args)
3740
case "list":
3841
return cmd.List(args)
3942
case "info":

0 commit comments

Comments
 (0)