diff --git a/cmd/declpac/main.go b/cmd/declpac/main.go index 55e062b..76b6f2f 100644 --- a/cmd/declpac/main.go +++ b/cmd/declpac/main.go @@ -20,6 +20,7 @@ type Config struct { StateFiles []string NoConfirm bool DryRun bool + Verbose bool } func main() { @@ -40,8 +41,15 @@ func main() { Usage: "Simulate the sync without making changes", Destination: &cfg.DryRun, }, + &cli.BoolFlag{ + Name: "verbose", + Aliases: []string{"v"}, + Usage: "Enable verbose output", + Destination: &cfg.Verbose, + }, }, Action: func(ctx context.Context, cmd *cli.Command) error { + log.Verbose = cfg.Verbose return run(cfg) }, } @@ -53,14 +61,14 @@ func main() { func run(cfg *Config) error { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] run: starting...\n") + log.Debug("run: starting...") packages, err := input.ReadPackages(cfg.StateFiles) if err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) return err } - fmt.Fprintf(os.Stderr, "[debug] run: packages read (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("run: packages read (%.2fs)", time.Since(start).Seconds()) merged := merge.Merge(packages) @@ -71,7 +79,7 @@ func run(cfg *Config) error { return err } fmt.Println(output.Format(result)) - fmt.Fprintf(os.Stderr, "[debug] run: dry-run done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("run: dry-run done (%.2fs)", time.Since(start).Seconds()) return nil } @@ -88,6 +96,6 @@ func run(cfg *Config) error { } fmt.Println(output.Format(result)) - fmt.Fprintf(os.Stderr, "[debug] run: sync done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("run: sync done (%.2fs)", time.Since(start).Seconds()) return nil } diff --git a/pkg/fetch/alpm/alpm.go b/pkg/fetch/alpm/alpm.go index 48f5ee8..0d2809c 100644 --- a/pkg/fetch/alpm/alpm.go +++ b/pkg/fetch/alpm/alpm.go @@ -2,10 +2,10 @@ package alpm import ( "fmt" - "os" "time" "github.com/Jguer/dyalpm" + "github.com/Riyyi/declpac/pkg/log" ) var ( @@ -21,7 +21,7 @@ type Handle struct { func New() (*Handle, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] alpm.New: starting...\n") + log.Debug("alpm.New: starting...") handle, err := dyalpm.Initialize(Root, PacmanState) if err != nil { @@ -48,7 +48,7 @@ func New() (*Handle, error) { } } - fmt.Fprintf(os.Stderr, "[debug] alpm.New: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("alpm.New: done (%.2fs)", time.Since(start).Seconds()) return &Handle{ handle: handle, localDB: localDB, @@ -64,7 +64,7 @@ func (h *Handle) Release() error { } func registerSyncDBs(handle dyalpm.Handle) ([]dyalpm.Database, error) { - fmt.Fprintf(os.Stderr, "[debug] registerSyncDBs: starting...\n") + log.Debug("registerSyncDBs: starting...") repos := []string{"core", "extra", "multilib"} var dbs []dyalpm.Database @@ -86,13 +86,13 @@ func registerSyncDBs(handle dyalpm.Handle) ([]dyalpm.Database, error) { } } - fmt.Fprintf(os.Stderr, "[debug] registerSyncDBs: done (%d dbs)\n", len(dbs)) + log.Debug("registerSyncDBs: done (%d dbs)", len(dbs)) return dbs, nil } func (h *Handle) LocalPackages() (map[string]dyalpm.Package, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] LocalPackages: starting...\n") + log.Debug("LocalPackages: starting...") localPkgs := make(map[string]dyalpm.Package) @@ -104,13 +104,13 @@ func (h *Handle) LocalPackages() (map[string]dyalpm.Package, error) { return nil, fmt.Errorf("failed to iterate local package cache: %w", err) } - fmt.Fprintf(os.Stderr, "[debug] LocalPackages: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("LocalPackages: done (%.2fs)", time.Since(start).Seconds()) return localPkgs, nil } func (h *Handle) SyncPackages(pkgNames []string) (map[string]dyalpm.Package, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] SyncPackages: starting...\n") + log.Debug("SyncPackages: starting...") syncPkgs := make(map[string]dyalpm.Package) pkgSet := make(map[string]bool) @@ -132,6 +132,6 @@ func (h *Handle) SyncPackages(pkgNames []string) (map[string]dyalpm.Package, err } } - fmt.Fprintf(os.Stderr, "[debug] SyncPackages: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("SyncPackages: done (%.2fs)", time.Since(start).Seconds()) return syncPkgs, nil } diff --git a/pkg/fetch/aur/aur.go b/pkg/fetch/aur/aur.go index 60bea0a..95feea7 100644 --- a/pkg/fetch/aur/aur.go +++ b/pkg/fetch/aur/aur.go @@ -2,12 +2,12 @@ package aur import ( "encoding/json" - "fmt" "io" "net/http" "net/url" - "os" "time" + + "github.com/Riyyi/declpac/pkg/log" ) var AURInfoURL = "https://aur.archlinux.org/rpc?v=5&type=info" @@ -35,7 +35,7 @@ func New() *Client { func (c *Client) Fetch(packages []string) (map[string]Package, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] aur.Fetch: starting...\n") + log.Debug("aur.Fetch: starting...") result := make(map[string]Package) @@ -51,7 +51,7 @@ func (c *Client) Fetch(packages []string) (map[string]Package, error) { } if len(uncached) == 0 { - fmt.Fprintf(os.Stderr, "[debug] aur.Fetch: done (cached) (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("aur.Fetch: done (cached) (%.2fs)", time.Since(start).Seconds()) for _, pkg := range packages { result[pkg] = c.cache[pkg] } @@ -84,7 +84,7 @@ func (c *Client) Fetch(packages []string) (map[string]Package, error) { result[r.Name] = r } - fmt.Fprintf(os.Stderr, "[debug] aur.Fetch: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("aur.Fetch: done (%.2fs)", time.Since(start).Seconds()) return result, nil } diff --git a/pkg/fetch/fetch.go b/pkg/fetch/fetch.go index 41306ba..bb4e6b8 100644 --- a/pkg/fetch/fetch.go +++ b/pkg/fetch/fetch.go @@ -2,11 +2,11 @@ package fetch import ( "fmt" - "os" "time" "github.com/Riyyi/declpac/pkg/fetch/alpm" "github.com/Riyyi/declpac/pkg/fetch/aur" + "github.com/Riyyi/declpac/pkg/log" ) type PackageInfo struct { @@ -24,7 +24,7 @@ type Fetcher struct { func New() (*Fetcher, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] fetch.Fetcher New: starting...\n") + log.Debug("fetch.Fetcher New: starting...") alpmHandle, err := alpm.New() if err != nil { @@ -33,7 +33,7 @@ func New() (*Fetcher, error) { aurClient := aur.New() - fmt.Fprintf(os.Stderr, "[debug] fetch.Fetcher New: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("fetch.Fetcher New: done (%.2fs)", time.Since(start).Seconds()) return &Fetcher{ alpmHandle: alpmHandle, aurClient: aurClient, @@ -62,7 +62,7 @@ func (f *Fetcher) BuildLocalPkgMap() (map[string]interface{}, error) { func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] fetch.Resolve: starting...\n") + log.Debug("fetch.Resolve: starting...") result := make(map[string]*PackageInfo) for _, pkg := range packages { @@ -73,7 +73,7 @@ func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) { if err != nil { return nil, err } - fmt.Fprintf(os.Stderr, "[debug] fetch.Resolve: sync db check done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("fetch.Resolve: sync db check done (%.2fs)", time.Since(start).Seconds()) for pkg := range syncPkgs { result[pkg].Exists = true @@ -84,7 +84,7 @@ func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) { if err != nil { return nil, err } - fmt.Fprintf(os.Stderr, "[debug] fetch.Resolve: local pkgs built (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("fetch.Resolve: local pkgs built (%.2fs)", time.Since(start).Seconds()) for pkg := range localPkgs { if info, ok := result[pkg]; ok { @@ -101,7 +101,7 @@ func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) { if len(notInSync) > 0 { if _, err := f.aurClient.Fetch(notInSync); err != nil { - fmt.Fprintf(os.Stderr, "[debug] fetch.Resolve: aur fetch error: %v\n", err) + log.Debug("fetch.Resolve: aur fetch error: %v", err) } for _, pkg := range packages { @@ -127,6 +127,6 @@ func (f *Fetcher) Resolve(packages []string) (map[string]*PackageInfo, error) { } } - fmt.Fprintf(os.Stderr, "[debug] fetch.Resolve: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("fetch.Resolve: done (%.2fs)", time.Since(start).Seconds()) return result, nil } diff --git a/pkg/log/log.go b/pkg/log/log.go index d0e9127..c9152c9 100644 --- a/pkg/log/log.go +++ b/pkg/log/log.go @@ -11,6 +11,16 @@ import ( // ----------------------------------------- var logFile *os.File +var Verbose bool + +// ----------------------------------------- + +func Debug(format string, args ...interface{}) { + if !Verbose { + return + } + fmt.Fprintf(os.Stderr, "[debug] "+format+"\n", args...) +} // ----------------------------------------- diff --git a/pkg/pacman/pacman.go b/pkg/pacman/pacman.go index 9ae52d7..d3cf809 100644 --- a/pkg/pacman/pacman.go +++ b/pkg/pacman/pacman.go @@ -15,7 +15,7 @@ import ( func Sync(packages []string) (*output.Result, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] Sync: starting...\n") + log.Debug("Sync: starting...") list, err := read.List() if err != nil { @@ -32,36 +32,35 @@ func Sync(packages []string) (*output.Result, error) { return nil, err } } - fmt.Fprintf(os.Stderr, "[debug] Sync: database fresh (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("Sync: database fresh (%.2fs)", time.Since(start).Seconds()) f, err := fetch.New() if err != nil { return nil, err } defer f.Close() - fmt.Fprintf(os.Stderr, "[debug] Sync: initialized fetcher (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("Sync: initialized fetcher (%.2fs)", time.Since(start).Seconds()) - fmt.Fprintf(os.Stderr, "[debug] Sync: categorizing packages...\n") + log.Debug("Sync: categorizing packages...") pacmanPkgs, aurPkgs, err := categorizePackages(f, packages) if err != nil { return nil, err } - fmt.Fprintf(os.Stderr, "[debug] Sync: packages categorized (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("Sync: packages categorized (%.2fs)", time.Since(start).Seconds()) if len(pacmanPkgs) > 0 { - fmt.Fprintf(os.Stderr, "[debug] Sync: syncing %d pacman packages...\n", len(pacmanPkgs)) + log.Debug("Sync: syncing %d pacman packages...", len(pacmanPkgs)) if err := sync.SyncPackages(pacmanPkgs, log.GetLogWriter()); err != nil { return nil, err } - fmt.Fprintf(os.Stderr, "[debug] Sync: pacman packages synced (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("Sync: pacman packages synced (%.2fs)", time.Since(start).Seconds()) } for _, pkg := range aurPkgs { if slices.Contains(list, pkg) { - fmt.Fprintf(os.Stderr, "[debug] Sync: AUR package %s already installed, skipping...\n", pkg) continue } - fmt.Fprintf(os.Stderr, "[debug] Sync: installing AUR package %s...\n", pkg) + log.Debug("Sync: installing AUR package %s...", pkg) aurInfo, ok := f.GetAURPackage(pkg) if !ok { return nil, fmt.Errorf("AUR package not found in cache: %s", pkg) @@ -69,18 +68,18 @@ func Sync(packages []string) (*output.Result, error) { if err := sync.InstallAUR(pkg, aurInfo.PackageBase, log.GetLogWriter()); err != nil { return nil, err } - fmt.Fprintf(os.Stderr, "[debug] Sync: AUR package %s installed (%.2fs)\n", pkg, time.Since(start).Seconds()) + log.Debug("Sync: AUR package %s installed (%.2fs)", pkg, time.Since(start).Seconds()) } - fmt.Fprintf(os.Stderr, "[debug] Sync: marking all as deps...\n") + log.Debug("Sync: marking all as deps...") markAllAsDeps() - fmt.Fprintf(os.Stderr, "[debug] Sync: all marked as deps (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("Sync: all marked as deps (%.2fs)", time.Since(start).Seconds()) - fmt.Fprintf(os.Stderr, "[debug] Sync: marking state packages as explicit...\n") + log.Debug("Sync: marking state packages as explicit...") if err := sync.MarkAs(packages, "explicit", log.GetLogWriter()); err != nil { fmt.Fprintf(os.Stderr, "warning: could not mark state packages as explicit: %v\n", err) } - fmt.Fprintf(os.Stderr, "[debug] Sync: state packages marked as explicit (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("Sync: state packages marked as explicit (%.2fs)", time.Since(start).Seconds()) removed, err := cleanupOrphans() if err != nil { @@ -95,7 +94,7 @@ func Sync(packages []string) (*output.Result, error) { installedCount := max(after-before, 0) - fmt.Fprintf(os.Stderr, "[debug] Sync: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("Sync: done (%.2fs)", time.Since(start).Seconds()) return &output.Result{ Installed: installedCount, Removed: removed, @@ -104,7 +103,7 @@ func Sync(packages []string) (*output.Result, error) { func categorizePackages(f *fetch.Fetcher, packages []string) (pacmanPkgs, aurPkgs []string, err error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] categorizePackages: starting...\n") + log.Debug("categorizePackages: starting...") resolved, err := f.Resolve(packages) if err != nil { @@ -124,13 +123,13 @@ func categorizePackages(f *fetch.Fetcher, packages []string) (pacmanPkgs, aurPkg } } - fmt.Fprintf(os.Stderr, "[debug] categorizePackages: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("categorizePackages: done (%.2fs)", time.Since(start).Seconds()) return pacmanPkgs, aurPkgs, nil } func markAllAsDeps() error { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] markAllAsDeps: starting...\n") + log.Debug("markAllAsDeps: starting...") packages, err := read.List() if err != nil || len(packages) == 0 { @@ -142,13 +141,13 @@ func markAllAsDeps() error { return err } - fmt.Fprintf(os.Stderr, "[debug] markAllAsDeps: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("markAllAsDeps: done (%.2fs)", time.Since(start).Seconds()) return nil } func cleanupOrphans() (int, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] cleanupOrphans: starting...\n") + log.Debug("cleanupOrphans: starting...") orphans, err := read.ListOrphans() if err != nil { @@ -162,6 +161,6 @@ func cleanupOrphans() (int, error) { return 0, err } - fmt.Fprintf(os.Stderr, "[debug] cleanupOrphans: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("cleanupOrphans: done (%.2fs)", time.Since(start).Seconds()) return removed, nil } diff --git a/pkg/pacman/read/read.go b/pkg/pacman/read/read.go index d41e139..c358d98 100644 --- a/pkg/pacman/read/read.go +++ b/pkg/pacman/read/read.go @@ -8,6 +8,7 @@ import ( "time" "github.com/Riyyi/declpac/pkg/fetch" + "github.com/Riyyi/declpac/pkg/log" "github.com/Riyyi/declpac/pkg/output" ) @@ -15,7 +16,7 @@ var LockFile = "/var/lib/pacman/db.lock" func List() ([]string, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] List: starting...\n") + log.Debug("List: starting...") cmd := exec.Command("pacman", "-Qq") output, err := cmd.Output() @@ -28,13 +29,13 @@ func List() ([]string, error) { list = nil } - fmt.Fprintf(os.Stderr, "[debug] List: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("List: done (%.2fs)", time.Since(start).Seconds()) return list, nil } func ListOrphans() ([]string, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] ListOrphans: starting...\n") + log.Debug("ListOrphans: starting...") cmd := exec.Command("pacman", "-Qdtq") output, err := cmd.Output() @@ -47,7 +48,7 @@ func ListOrphans() ([]string, error) { orphans = orphans[1:] } - fmt.Fprintf(os.Stderr, "[debug] ListOrphans: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("ListOrphans: done (%.2fs)", time.Since(start).Seconds()) return orphans, nil } @@ -63,20 +64,20 @@ func DBFreshness() (bool, error) { func DryRun(packages []string) (*output.Result, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] DryRun: starting...\n") + log.Debug("DryRun: starting...") f, err := fetch.New() if err != nil { return nil, err } defer f.Close() - fmt.Fprintf(os.Stderr, "[debug] DryRun: initialized fetcher (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("DryRun: initialized fetcher (%.2fs)", time.Since(start).Seconds()) resolved, err := f.Resolve(packages) if err != nil { return nil, err } - fmt.Fprintf(os.Stderr, "[debug] DryRun: packages resolved (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("DryRun: packages resolved (%.2fs)", time.Since(start).Seconds()) var toInstall []string var aurPkgs []string @@ -91,13 +92,13 @@ func DryRun(packages []string) (*output.Result, error) { toInstall = append(toInstall, pkg) } } - fmt.Fprintf(os.Stderr, "[debug] DryRun: packages categorized (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("DryRun: packages categorized (%.2fs)", time.Since(start).Seconds()) orphans, err := ListOrphans() if err != nil { return nil, err } - fmt.Fprintf(os.Stderr, "[debug] DryRun: orphans listed (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("DryRun: orphans listed (%.2fs)", time.Since(start).Seconds()) pkgSet := make(map[string]bool) for _, p := range packages { @@ -110,7 +111,7 @@ func DryRun(packages []string) (*output.Result, error) { } } - fmt.Fprintf(os.Stderr, "[debug] DryRun: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("DryRun: done (%.2fs)", time.Since(start).Seconds()) return &output.Result{ Installed: len(toInstall) + len(aurPkgs), Removed: len(toRemove), diff --git a/pkg/pacman/sync/sync.go b/pkg/pacman/sync/sync.go index 534060e..a59b10f 100644 --- a/pkg/pacman/sync/sync.go +++ b/pkg/pacman/sync/sync.go @@ -7,6 +7,8 @@ import ( "os/exec" "strings" "time" + + "github.com/Riyyi/declpac/pkg/log" ) type Result struct { @@ -16,7 +18,7 @@ type Result struct { func SyncPackages(packages []string, logWriter io.Writer) error { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] SyncPackages: starting...\n") + log.Debug("SyncPackages: starting...") if logWriter == nil { logWriter = os.Stderr @@ -33,13 +35,13 @@ func SyncPackages(packages []string, logWriter io.Writer) error { return fmt.Errorf("pacman sync failed: %w", err) } - fmt.Fprintf(os.Stderr, "[debug] SyncPackages: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("SyncPackages: done (%.2fs)", time.Since(start).Seconds()) return nil } func RefreshDB(logWriter io.Writer) error { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] RefreshDB: starting...\n") + log.Debug("RefreshDB: starting...") if logWriter == nil { logWriter = os.Stderr @@ -53,7 +55,7 @@ func RefreshDB(logWriter io.Writer) error { return fmt.Errorf("failed to refresh pacman database: %w", err) } - fmt.Fprintf(os.Stderr, "[debug] RefreshDB: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("RefreshDB: done (%.2fs)", time.Since(start).Seconds()) return nil } @@ -63,7 +65,7 @@ func MarkAs(packages []string, flag string, logWriter io.Writer) error { } start := time.Now() flagName := map[string]string{"deps": "asdeps", "explicit": "asexplicit"}[flag] - fmt.Fprintf(os.Stderr, "[debug] MarkAs(%s): starting...\n", flag) + log.Debug("MarkAs(%s): starting...", flag) if logWriter == nil { logWriter = os.Stderr @@ -80,20 +82,20 @@ func MarkAs(packages []string, flag string, logWriter io.Writer) error { return fmt.Errorf("mark as %s failed: %w", flag, err) } - fmt.Fprintf(os.Stderr, "[debug] MarkAs(%s): done (%.2fs)\n", flag, time.Since(start).Seconds()) + log.Debug("MarkAs(%s): done (%.2fs)", flag, time.Since(start).Seconds()) return nil } func RemoveOrphans(orphans []string, logWriter io.Writer) (int, error) { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] RemoveOrphans: starting...\n") + log.Debug("RemoveOrphans: starting...") if logWriter == nil { logWriter = os.Stderr } if len(orphans) == 0 { - fmt.Fprintf(os.Stderr, "[debug] RemoveOrphans: done (no orphans) (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("RemoveOrphans: done (no orphans) (%.2fs)", time.Since(start).Seconds()) return 0, nil } @@ -112,13 +114,13 @@ func RemoveOrphans(orphans []string, logWriter io.Writer) (int, error) { count := len(orphans) - fmt.Fprintf(os.Stderr, "[debug] RemoveOrphans: done (%d) (%.2fs)\n", count, time.Since(start).Seconds()) + log.Debug("RemoveOrphans: done (%d) (%.2fs)", count, time.Since(start).Seconds()) return count, nil } func InstallAUR(pkgName string, packageBase string, logWriter io.Writer) error { start := time.Now() - fmt.Fprintf(os.Stderr, "[debug] InstallAUR: starting...\n") + log.Debug("InstallAUR: starting...") if logWriter == nil { logWriter = os.Stderr @@ -150,7 +152,7 @@ func InstallAUR(pkgName string, packageBase string, logWriter io.Writer) error { if err := cloneCmd.Run(); err != nil { return fmt.Errorf("failed to clone AUR repo: %w", err) } - fmt.Fprintf(os.Stderr, "[debug] InstallAUR: cloned (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("InstallAUR: cloned (%.2fs)", time.Since(start).Seconds()) makepkgCmdStr := "su - " + sudoUser + " -c 'cd " + tmpDir + " && makepkg -s --noconfirm'" fmt.Fprintf(logWriter, "[cmd] %s\n", makepkgCmdStr) @@ -160,7 +162,7 @@ func InstallAUR(pkgName string, packageBase string, logWriter io.Writer) error { if err := makepkgCmd.Run(); err != nil { return fmt.Errorf("makepkg failed to build AUR package: %w", err) } - fmt.Fprintf(os.Stderr, "[debug] InstallAUR: built (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("InstallAUR: built (%.2fs)", time.Since(start).Seconds()) pkgFile, err := findPKGFile(tmpDir) if err != nil { @@ -175,7 +177,7 @@ func InstallAUR(pkgName string, packageBase string, logWriter io.Writer) error { if err := installCmd.Run(); err != nil { return fmt.Errorf("failed to install package: %w", err) } - fmt.Fprintf(os.Stderr, "[debug] InstallAUR: done (%.2fs)\n", time.Since(start).Seconds()) + log.Debug("InstallAUR: done (%.2fs)", time.Since(start).Seconds()) return nil }