Skip to content

Commit b53490f

Browse files
author
Ben Morgan
committed
Improve usage, error, and debug messages
1 parent ce9f862 commit b53490f

20 files changed

+140
-57
lines changed

add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func init() {
1919
}
2020

2121
var addCmd = &cobra.Command{
22-
Use: "add <pkgfile...>",
22+
Use: "add PKGFILE ...",
2323
Short: "Copy and add packages to the repository",
2424
Long: `Add (and copy if necessary) the package file to the repository.
2525

conf.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ var confCmd = &cobra.Command{
7070
configuration file. These can be created manually, or repoctl can
7171
create them for you.
7272
73-
Whether you already have a repository or not, creating a new config is
74-
sufficient:
73+
If you already have a repository, creating a new config is sufficient:
7574
7675
repoctl conf new /path/to/repository/database.db.tar.gz
7776
77+
Otherwise, make sure to run
78+
79+
repoctl reset
80+
81+
afterwards.
82+
7883
Repoctl supports multiple repository configuration through profiles.
7984
You can add a profile by editing the configuration file manually:
8085
@@ -189,7 +194,7 @@ var confEditCmd = &cobra.Command{
189194
}
190195

191196
var confNewCmd = &cobra.Command{
192-
Use: "new </path/to/repo/database>",
197+
Use: "new DBPATH",
193198
Short: "Create a new configuration file",
194199
Long: `Create a new initial configuration file.
195200

down.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func init() {
4040
}
4141

4242
var downCmd = &cobra.Command{
43-
Use: "down [pkgname...]",
43+
Use: "down [PKGNAME ...]",
4444
Aliases: []string{"download"},
4545
Short: "Download and extract tarballs from AUR",
4646
Long: `Download and extract tarballs from AUR for given packages.
@@ -170,11 +170,11 @@ func downDependencies(packages []string) (aur.Packages, error) {
170170
f.Close()
171171
}
172172
for _, u := range ups {
173-
fmt.Fprintf(os.Stderr, "warning: unknown package %s\n", u)
173+
fmt.Fprintf(os.Stderr, "Warning: unknown package %s\n", u)
174174
iter := g.To(g.NodeWithName(u).ID())
175175
for iter.Next() {
176176
node := iter.Node().(*graph.Node)
177-
fmt.Fprintf(os.Stderr, " required by: %s\n", node.PkgName())
177+
fmt.Fprintf(os.Stderr, " Required by: %s\n", node.PkgName())
178178
}
179179
}
180180
return aps, nil

list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func init() {
5353
}
5454

5555
var listCmd = &cobra.Command{
56-
Use: "list [regex]",
56+
Use: "list [REGEX]",
5757
Aliases: []string{"ls"},
5858
Short: "List packages that belong to the managed repository",
5959
Long: `List packages that belong to the managed repository.

main.go

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ package main
66

77
import (
88
"fmt"
9+
"io"
910
"os"
1011
"os/exec"
1112

1213
"github.com/cassava/repoctl/conf"
14+
"github.com/cassava/repoctl/pacman"
1315
"github.com/cassava/repoctl/repo"
1416
"github.com/goulash/color"
1517
"github.com/spf13/cobra"
@@ -67,8 +69,9 @@ packages from AUR.
6769
6870
Note that in all of these commands, the following terminology is used:
6971
70-
pkgname: is the name of the package, e.g. pacman
71-
pkgfile: is the path to a package file, e.g. pacman-3.5.3-i686.pkg.tar.xz
72+
PKGNAME: is the name of the package, e.g. pacman
73+
PKGFILE: is the path to a package file, e.g. pacman-3.5.3-i686.pkg.tar.xz
74+
DBPATH: is the (absolute) path to your repo database, e.g. /srv/sirius.db.tar.zst
7275
7376
There are several places that repoctl reads its configuration from.
7477
If $REPOCTL_CONFIG is set, then only this path is loaded. Otherwise,
@@ -85,12 +88,35 @@ In most systems then, repoctl will read:
8588
/etc/xdg/repoctl/config.toml
8689
/home/you/.config/repoctl/config.toml
8790
91+
---
92+
93+
If you are new to repoctl, perform the following commands to get started:
94+
95+
repoctl conf new DBPATH # Create a new configuration file
96+
repoctl conf edit # Edit the configuration file
97+
repoctl reset # Initialize the repository
98+
99+
You can then continue by building and adding packages:
100+
101+
repoctl search QUERY
102+
repoctl down -r PKGNAME
103+
# cd PKGNAME && makepkg
104+
repoctl add PKGFILE ...
105+
106+
And by viewing the status of your repository:
107+
108+
repoctl status
109+
88110
`,
89111
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
90112
// Prevent errors that we print being printed a second time by cobra.
91113
cmd.SilenceErrors = true
92114
cmd.SilenceUsage = true
93115

116+
if Conf.Debug {
117+
pacman.DebugWriter = newDebugWriter(Term)
118+
}
119+
94120
return nil
95121
},
96122
}
@@ -140,6 +166,9 @@ func ProfileInit(cmd *cobra.Command, args []string) error {
140166
if err != nil {
141167
return fmt.Errorf("cannot load profile %q: %s", name, err)
142168
}
169+
if Conf.Debug {
170+
Repo.Debug = newDebugWriter(Term)
171+
}
143172

144173
// 4. Run pre-action if defined.
145174
if Profile.PreAction != "" {
@@ -149,6 +178,26 @@ func ProfileInit(cmd *cobra.Command, args []string) error {
149178
return nil
150179
}
151180

181+
type debugWriter struct {
182+
term *color.Colorizer
183+
out io.Writer
184+
}
185+
186+
func newDebugWriter(term *color.Colorizer) *debugWriter {
187+
if term == nil {
188+
return nil
189+
}
190+
191+
return &debugWriter{
192+
term: term,
193+
out: os.Stderr,
194+
}
195+
}
196+
197+
func (w *debugWriter) Write(p []byte) (n int, err error) {
198+
return w.term.Fprintf(w.out, "@.%s", p)
199+
}
200+
152201
// ProfileTeardown should be used as the PostRunE part of every command
153202
// that needs to make use of the profile or the Repo.
154203
func ProfileTeardown(cmd *cobra.Command, args []string) error {

pacman/doc.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,18 @@
44

55
// Package pacman provides routines for dealing with Pacman packages.
66
package pacman
7+
8+
import (
9+
"fmt"
10+
"io"
11+
)
12+
13+
// DebugWriter is used to write debugging information from this module.
14+
// If it is nil, then no debugging messages are printed.
15+
var DebugWriter io.Writer = nil
16+
17+
func debugf(format string, obj ...interface{}) {
18+
if DebugWriter != nil {
19+
fmt.Fprintf(DebugWriter, format, obj...)
20+
}
21+
}

pacman/read-db.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ func IsDatabaseLocked(dbpath string) bool {
4444

4545
// ReadDatabase reads all the packages from a database file.
4646
func ReadDatabase(dbpath string) (Packages, error) {
47+
debugf("Read database %s\n", dbpath)
48+
4749
var dr io.ReadCloser
4850
var err error
4951

52+
if ex, err := osutil.FileExists(dbpath); !ex {
53+
if err != nil {
54+
return nil, fmt.Errorf("read database %s: %w", dbpath, err)
55+
}
56+
return nil, fmt.Errorf("read database %s: no such file", dbpath)
57+
}
58+
5059
dr, err = archive.NewDecompressor(dbpath)
5160
if err != nil {
5261
return nil, fmt.Errorf("read database %s: %w", dbpath, err)

pacman/read-fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func ReadEveryFileInDir(h errs.Handler, dirpath string) (Packages, error) {
9393
dirpath = filepath.Clean(dirpath)
9494
err := filepath.Walk(dirpath, func(filename string, info os.FileInfo, err error) error {
9595
if err != nil {
96-
return h(err)
96+
return h(fmt.Errorf("read file %s: %w", filename, err))
9797
}
9898
if info.Mode().IsDir() {
9999
if filename == dirpath {

pacman/read-pkg.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import (
1919
// Read reads the package information from a pacman package
2020
// and returns it in the Package datatype.
2121
func Read(filename string) (*Package, error) {
22+
debugf("Read package %s\n", filename)
2223
bs, err := archive.ReadFileFromArchive(filename, ".PKGINFO")
2324
if err != nil {
24-
return nil, err
25+
return nil, fmt.Errorf("read package %s: %w", filename, err)
2526
}
2627

2728
r := bytes.NewReader(bs)
2829
info, err := readFilePkgInfo(r)
2930
if err != nil {
30-
return nil, err
31+
return nil, fmt.Errorf("read package %s: %w", filename, err)
3132
}
3233

3334
info.Filename = filename

query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func init() {
2020
}
2121

2222
var queryCmd = &cobra.Command{
23-
Use: "query [pkgname...]",
23+
Use: "query [PKGNAME ...]",
2424
Short: "Query package information from AUR",
2525
Long: `Query package information from AUR.
2626
@@ -60,7 +60,7 @@ var queryCmd = &cobra.Command{
6060
return err
6161
}
6262
for _, n := range nfe.Names {
63-
fmt.Fprintf(os.Stderr, "warning: unknown package %s\n", n)
63+
fmt.Fprintf(os.Stderr, "Warning: unknown package %s\n", n)
6464
}
6565
}
6666

0 commit comments

Comments
 (0)