From b3f4c2e90d2906ef5d2e7268cbc74c8382543ef9 Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Wed, 24 Dec 2025 16:14:33 +0000 Subject: [PATCH] get rid of stdin/out/err in context since we're agentless now, we can simplify a lot. --- appcontext/appcontext.go | 3 - main.go | 32 ++--- subcommands/agent/cached.go | 4 +- subcommands/archive/archive.go | 2 +- subcommands/backup/backup.go | 8 +- subcommands/cat/cat.go | 5 +- subcommands/check/check.go | 3 +- subcommands/config/config.go | 32 ++--- subcommands/config/policy.go | 13 +- subcommands/diag/blob.go | 12 +- subcommands/diag/blob_search.go | 8 +- subcommands/diag/contenttype.go | 2 +- subcommands/diag/dirpack.go | 4 +- subcommands/diag/locks.go | 7 +- subcommands/diag/object.go | 10 +- subcommands/diag/packfile.go | 15 +- subcommands/diag/repository.go | 78 +++++------ subcommands/diag/search.go | 2 +- subcommands/diag/snapshot.go | 124 ++++++++--------- subcommands/diag/state.go | 16 +-- subcommands/diag/vfs.go | 184 ++++++++++++------------- subcommands/diag/xattrs.go | 2 +- subcommands/diff/diff.go | 4 +- subcommands/digest/digest.go | 2 +- subcommands/info/errors.go | 2 +- subcommands/info/repository.go | 82 +++++------ subcommands/info/snapshot.go | 112 +++++++-------- subcommands/locate/locate.go | 2 +- subcommands/login/login.go | 2 +- subcommands/login/token-create.go | 2 +- subcommands/ls/ls.go | 6 +- subcommands/maintenance/maintenance.go | 24 ++-- subcommands/pkg/build.go | 2 +- subcommands/pkg/create.go | 2 +- subcommands/pkg/list.go | 4 +- subcommands/prune/prune.go | 6 +- subcommands/rm/rm.go | 4 +- subcommands/service/disable.go | 2 +- subcommands/service/enable.go | 2 +- subcommands/service/list.go | 2 +- subcommands/service/show.go | 5 +- subcommands/service/status.go | 4 +- subcommands/ui/ui.go | 3 +- subcommands/version/version_test.go | 2 +- ui/v2/ui.go | 2 +- 45 files changed, 424 insertions(+), 420 deletions(-) diff --git a/appcontext/appcontext.go b/appcontext/appcontext.go index 1b2f2697f..9fbcfdf78 100644 --- a/appcontext/appcontext.go +++ b/appcontext/appcontext.go @@ -56,9 +56,6 @@ func (ctx *AppContext) ImporterOpts() *importer.Options { Architecture: ctx.Architecture, CWD: ctx.CWD, MaxConcurrency: ctx.MaxConcurrency, - Stdin: ctx.Stdin, - Stdout: ctx.Stdout, - Stderr: ctx.Stderr, } } diff --git a/main.go b/main.go index 92088ab2d..51ad49ef5 100644 --- a/main.go +++ b/main.go @@ -210,7 +210,7 @@ func entryPoint() int { if opt_disableSecurityCheck { ctx.GetCookies().SetDisabledSecurityCheck() - fmt.Fprintln(ctx.Stdout, "security check disabled !") + fmt.Println("security check disabled !") return 1 } else { opt_disableSecurityCheck = ctx.GetCookies().IsDisabledSecurityCheck() @@ -218,7 +218,7 @@ func entryPoint() int { if opt_enableSecurityCheck { ctx.GetCookies().RemoveDisabledSecurityCheck() - fmt.Fprintln(ctx.Stdout, "security check enabled !") + fmt.Println("security check enabled !") return 1 } @@ -486,20 +486,20 @@ func checkUpdate(ctx *appcontext.AppContext, disableSecurityCheck bool) { return } - fmt.Fprintln(ctx.Stdout, "Welcome to plakar !") - fmt.Fprintln(ctx.Stdout, "") - fmt.Fprintln(ctx.Stdout, "By default, plakar checks for security updates on the releases feed once every 24h.") - fmt.Fprintln(ctx.Stdout, "It will notify you if there are important updates that you need to install.") - fmt.Fprintln(ctx.Stdout, "") - fmt.Fprintln(ctx.Stdout, "If you prefer to watch yourself, you can disable this permanently by running:") - fmt.Fprintln(ctx.Stdout, "") - fmt.Fprintln(ctx.Stdout, "\tplakar -disable-security-check") - fmt.Fprintln(ctx.Stdout, "") - fmt.Fprintln(ctx.Stdout, "If you change your mind, run:") - fmt.Fprintln(ctx.Stdout, "") - fmt.Fprintln(ctx.Stdout, "\tplakar -enable-security-check") - fmt.Fprintln(ctx.Stdout, "") - fmt.Fprintln(ctx.Stdout, "EOT") + fmt.Println("Welcome to plakar !") + fmt.Println("") + fmt.Println("By default, plakar checks for security updates on the releases feed once every 24h.") + fmt.Println("It will notify you if there are important updates that you need to install.") + fmt.Println("") + fmt.Println("If you prefer to watch yourself, you can disable this permanently by running:") + fmt.Println("") + fmt.Println("\tplakar -disable-security-check") + fmt.Println("") + fmt.Println("If you change your mind, run:") + fmt.Println("") + fmt.Println("\tplakar -enable-security-check") + fmt.Println("") + fmt.Println("EOT") return } diff --git a/subcommands/agent/cached.go b/subcommands/agent/cached.go index b244e1df3..cead9762f 100644 --- a/subcommands/agent/cached.go +++ b/subcommands/agent/cached.go @@ -272,7 +272,7 @@ func (cmd *Cached) handleCachedClient(ctx *appcontext.AppContext, conn net.Conn) return } ctx.GetLogger().Warn("Failed to decode RPC: %v", err) - fmt.Fprintf(clientContext.Stderr, "%s\n", err) + //fmt.Fprintf(clientContext.Stderr, "%s\n", err) return } @@ -296,7 +296,7 @@ func (cmd *Cached) handleCachedClient(ctx *appcontext.AppContext, conn net.Conn) subcommand := &cached.CachedReq{} if err := msgpack.Unmarshal(request, subcommand); err != nil { ctx.GetLogger().Warn("Failed to decode client request: %v", err) - fmt.Fprintf(clientContext.Stderr, "Failed to decode client request: %s\n", err) + //fmt.Fprintf(clientContext.Stderr, "Failed to decode client request: %s\n", err) return } diff --git a/subcommands/archive/archive.go b/subcommands/archive/archive.go index 2c6935e1d..0e93f6ef8 100644 --- a/subcommands/archive/archive.go +++ b/subcommands/archive/archive.go @@ -85,7 +85,7 @@ func (cmd *Archive) Execute(ctx *appcontext.AppContext, repo *repository.Reposit var out io.Writer if cmd.Output == "-" { - out = ctx.Stdout + out = os.Stdout } else { tmp, err := os.CreateTemp("", "plakar-archive-") if err != nil { diff --git a/subcommands/backup/backup.go b/subcommands/backup/backup.go index 41b846e3a..f3172b6dd 100644 --- a/subcommands/backup/backup.go +++ b/subcommands/backup/backup.go @@ -397,8 +397,8 @@ func executeHook(ctx *appcontext.AppContext, hook string) error { cmd = exec.Command("/bin/sh", "-c", hook) } - cmd.Stdout = ctx.Stdout - cmd.Stderr = ctx.Stderr + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr return cmd.Run() } @@ -436,10 +436,10 @@ func dryrun(ctx *appcontext.AppContext, imp importer.Importer, excludePatterns [ switch { case record.Error != nil: errors = true - fmt.Fprintf(ctx.Stderr, "%s: %s\n", + fmt.Fprintf(os.Stderr, "%s: %s\n", record.Error.Pathname, record.Error.Err) case record.Record != nil: - fmt.Fprintln(ctx.Stdout, record.Record.Pathname) + fmt.Println(record.Record.Pathname) record.Record.Close() } } diff --git a/subcommands/cat/cat.go b/subcommands/cat/cat.go index 7040158d4..f2f4352d1 100644 --- a/subcommands/cat/cat.go +++ b/subcommands/cat/cat.go @@ -22,6 +22,7 @@ import ( "flag" "fmt" "io" + "os" "github.com/PlakarKorp/kloset/locate" "github.com/PlakarKorp/kloset/repository" @@ -153,7 +154,7 @@ func (cmd *Cat) Execute(ctx *appcontext.AppContext, repo *repository.Repository) break } - errFormat := formatter.Format(ctx.Stdout, style, iterator) + errFormat := formatter.Format(os.Stdout, style, iterator) if errFormat != nil { ctx.GetLogger().Error("cat: %s: %s", pathname, errFormat) errors++ @@ -173,7 +174,7 @@ func (cmd *Cat) Execute(ctx *appcontext.AppContext, repo *repository.Repository) } } } else { - _, err = io.Copy(ctx.Stdout, rd) + _, err = io.Copy(os.Stdout, rd) } file.Close() if err != nil { diff --git a/subcommands/check/check.go b/subcommands/check/check.go index 85bd3aef0..e8e797fa8 100644 --- a/subcommands/check/check.go +++ b/subcommands/check/check.go @@ -20,6 +20,7 @@ import ( "encoding/hex" "flag" "fmt" + "os" "github.com/PlakarKorp/kloset/locate" "github.com/PlakarKorp/kloset/repository" @@ -90,7 +91,7 @@ func (cmd *Check) Execute(ctx *appcontext.AppContext, repo *repository.Repositor cmd.LocateOptions.Filters.IDs = []string{prefix} snapshotIDs, err := locate.LocateSnapshotIDs(repo, cmd.LocateOptions) if err != nil { - fmt.Fprintln(ctx.Stderr, err) + fmt.Fprintln(os.Stderr, err) return 1, err } diff --git a/subcommands/config/config.go b/subcommands/config/config.go index 7d76f6633..72ddfdc11 100644 --- a/subcommands/config/config.go +++ b/subcommands/config/config.go @@ -87,7 +87,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a case "add": p := flag.NewFlagSet("add", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [=...]\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s [=...]\n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) @@ -115,7 +115,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a case "check": p := flag.NewFlagSet("check", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s \n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s \n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) @@ -170,12 +170,12 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a flags.StringVar(&opt_config, "config", "", "import from a file") flags.BoolVar(&opt_overwrite, "overwrite", false, "overwrite existing configurations") flags.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [OPTIONS]
...\n", cmd, flags.Name()) + fmt.Printf("Usage: plakar %s %s [OPTIONS]
...\n", cmd, flags.Name()) flags.PrintDefaults() } flags.Parse(args) - var rd io.Reader = ctx.Stdin + var rd io.Reader = os.Stdin if opt_config != "" { if strings.HasPrefix(opt_config, "http://") || strings.HasPrefix(opt_config, "https://") { resp, err := http.Get(opt_config) @@ -210,7 +210,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a if flags.NArg() == 0 { for name, section := range newConfMap { if hasFunc(name) && !opt_overwrite { - fmt.Fprintf(ctx.Stderr, "%s %q already exists, skipping\n", cmd, name) + fmt.Fprintf(os.Stderr, "%s %q already exists, skipping\n", cmd, name) continue } cfgMap[name] = make(map[string]string) @@ -223,16 +223,16 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a targetName = normalizeName(origName) } if origName == "" || targetName == "" { - fmt.Fprintf(ctx.Stderr, "%s empty section name in %q, skipping\n", cmd, requestedName) + fmt.Fprintf(os.Stderr, "%s empty section name in %q, skipping\n", cmd, requestedName) continue } if hasFunc(targetName) && !opt_overwrite { - fmt.Fprintf(ctx.Stderr, "%s %q already exists, skipping\n", cmd, targetName) + fmt.Fprintf(os.Stderr, "%s %q already exists, skipping\n", cmd, targetName) continue } if section, ok := newConfMap[origName]; !ok { - fmt.Fprintf(ctx.Stderr, "%s %q does not exist in config\n", cmd, origName) + fmt.Fprintf(os.Stderr, "%s %q does not exist in config\n", cmd, origName) continue } else { cfgMap[targetName] = make(map[string]string) @@ -248,7 +248,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a case "rm": p := flag.NewFlagSet("rm", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s \n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s \n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) @@ -267,7 +267,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a case "set": p := flag.NewFlagSet("set", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s =...\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s =...\n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) @@ -295,7 +295,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a var opt_show_secrets bool p := flag.NewFlagSet("show", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [...]\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s [...]\n", cmd, p.Name()) p.PrintDefaults() } @@ -318,7 +318,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a for _, name := range names { name = normalizeName(name) if !hasFunc(name) { - fmt.Fprintf(ctx.Stderr, "%s %q does not exist\n", cmd, name) + fmt.Fprintf(os.Stderr, "%s %q does not exist\n", cmd, name) hasErrors = true continue } @@ -352,11 +352,11 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a var err error if opt_json { - err = json.NewEncoder(ctx.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]}) + err = json.NewEncoder(os.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]}) } else if opt_ini { - err = MarshalINISections(name, cfgMap[name], ctx.Stdout) + err = MarshalINISections(name, cfgMap[name], os.Stdout) } else { - err = yaml.NewEncoder(ctx.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]}) + err = yaml.NewEncoder(os.Stdout).Encode(map[string]map[string]string{name: cfgMap[name]}) } if err != nil { return fmt.Errorf("failed to encode store %q: %w", name, err) @@ -370,7 +370,7 @@ func dispatchSubcommand(ctx *appcontext.AppContext, cmd string, subcmd string, a case "unset": p := flag.NewFlagSet("unset", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s ...\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s ...\n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) diff --git a/subcommands/config/policy.go b/subcommands/config/policy.go index f5c15d758..e093ef2b5 100644 --- a/subcommands/config/policy.go +++ b/subcommands/config/policy.go @@ -3,6 +3,7 @@ package config import ( "flag" "fmt" + "os" "path/filepath" "strings" @@ -57,7 +58,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin case "add": p := flag.NewFlagSet("add", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [=...]\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s [=...]\n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) @@ -85,7 +86,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin case "rm": p := flag.NewFlagSet("rm", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s \n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s \n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) @@ -104,7 +105,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin case "set": p := flag.NewFlagSet("set", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s =...\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s =...\n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) @@ -133,7 +134,7 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin var opt_yaml bool p := flag.NewFlagSet("show", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s [...]\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s [...]\n", cmd, p.Name()) p.PrintDefaults() } @@ -154,12 +155,12 @@ func dispatchPolicy(ctx *appcontext.AppContext, cmd, subcmd string, args []strin format = "ini" } - return config.Dump(ctx.Stdout, format, names) + return config.Dump(os.Stdout, format, names) case "unset": p := flag.NewFlagSet("unset", flag.ExitOnError) p.Usage = func() { - fmt.Fprintf(ctx.Stdout, "Usage: plakar %s %s ...\n", cmd, p.Name()) + fmt.Printf("Usage: plakar %s %s ...\n", cmd, p.Name()) p.PrintDefaults() } p.Parse(args) diff --git a/subcommands/diag/blob.go b/subcommands/diag/blob.go index 721066038..8cf0293de 100644 --- a/subcommands/diag/blob.go +++ b/subcommands/diag/blob.go @@ -65,7 +65,7 @@ func (cmd *DiagBlob) Execute(ctx *appcontext.AppContext, repo *repository.Reposi return 1, fmt.Errorf("failed to deserialize %s %x: %w", blobtype, mac, err) } - fmt.Fprintf(ctx.Stdout, "%+v\n", hdr) + fmt.Printf("%+v\n", hdr) case resources.RT_OBJECT: obj, err := objects.NewObjectFromBytes(buf) @@ -73,7 +73,7 @@ func (cmd *DiagBlob) Execute(ctx *appcontext.AppContext, repo *repository.Reposi return 1, fmt.Errorf("failed to deserialize %s %x: %w", blobtype, mac, err) } - fmt.Fprintf(ctx.Stdout, "%+v\n", obj) + fmt.Printf("%+v\n", obj) case resources.RT_CHUNK: chunk, err := objects.NewChunkFromBytes(buf) @@ -81,7 +81,7 @@ func (cmd *DiagBlob) Execute(ctx *appcontext.AppContext, repo *repository.Reposi return 1, fmt.Errorf("failed to deserialize %s %x: %w", blobtype, mac, err) } - fmt.Fprintf(ctx.Stdout, "%+v\n", chunk) + fmt.Printf("%+v\n", chunk) case resources.RT_VFS_ENTRY: entry, err := vfs.EntryFromBytes(buf) @@ -89,7 +89,7 @@ func (cmd *DiagBlob) Execute(ctx *appcontext.AppContext, repo *repository.Reposi return 1, fmt.Errorf("failed to deserialize %s %x: %w", blobtype, mac, err) } - fmt.Fprintf(ctx.Stdout, "%+v\n", entry) + fmt.Printf("%+v\n", entry) case resources.RT_ERROR_ENTRY: error, err := vfs.ErrorItemFromBytes(buf) @@ -97,7 +97,7 @@ func (cmd *DiagBlob) Execute(ctx *appcontext.AppContext, repo *repository.Reposi return 1, fmt.Errorf("failed to deserialize %s %x: %w", blobtype, mac, err) } - fmt.Fprintf(ctx.Stdout, "%+v\n", error) + fmt.Printf("%+v\n", error) case resources.RT_XATTR_ENTRY: xattr, err := vfs.XattrFromBytes(buf) @@ -105,7 +105,7 @@ func (cmd *DiagBlob) Execute(ctx *appcontext.AppContext, repo *repository.Reposi return 1, fmt.Errorf("failed to deserialize %s %x: %w", blobtype, mac, err) } - fmt.Fprintf(ctx.Stdout, "%+v\n", xattr) + fmt.Printf("%+v\n", xattr) default: return 1, fmt.Errorf("don't know how to deserialize %s", blobtype) diff --git a/subcommands/diag/blob_search.go b/subcommands/diag/blob_search.go index d69fbe5ae..e64127739 100644 --- a/subcommands/diag/blob_search.go +++ b/subcommands/diag/blob_search.go @@ -35,7 +35,7 @@ func (cmd *DiagBlobSearch) Parse(ctx *appcontext.AppContext, args []string) erro } func (cmd *DiagBlobSearch) Execute(ctx *appcontext.AppContext, repo *repository.Repository) (int, error) { - fmt.Fprintf(ctx.Stdout, "Warning this command is slow and expensive. Use with caution.\n") + fmt.Printf("Warning this command is slow and expensive. Use with caution.\n") if len(cmd.ObjectID) != 64 { return 1, fmt.Errorf("invalid object hash: %s", cmd.ObjectID) @@ -61,7 +61,7 @@ func (cmd *DiagBlobSearch) Execute(ctx *appcontext.AppContext, repo *repository. for _, entry := range p.Index { if entry.MAC == needleMAC { - fmt.Fprintf(ctx.Stdout, "Found candidate [%x] in packfile [%x] at : %d %d %s\n", entry.MAC, packfileMac, entry.Offset, entry.Length, entry.Type) + fmt.Printf("Found candidate [%x] in packfile [%x] at : %d %d %s\n", entry.MAC, packfileMac, entry.Offset, entry.Length, entry.Type) if entry.Type == resources.RT_OBJECT { rd, err := repo.GetPackfileBlob(state.Location{Packfile: packfileMac, Offset: entry.Offset, Length: entry.Length}) if err != nil { @@ -78,8 +78,8 @@ func (cmd *DiagBlobSearch) Execute(ctx *appcontext.AppContext, repo *repository. return 1, err } - fmt.Fprintf(ctx.Stdout, "object: %x\n", object.ContentMAC) - fmt.Fprintln(ctx.Stdout, " type:", object.ContentType) + fmt.Printf("object: %x\n", object.ContentMAC) + fmt.Println(" type:", object.ContentType) } } diff --git a/subcommands/diag/contenttype.go b/subcommands/diag/contenttype.go index 8def9447b..ad2f2a860 100644 --- a/subcommands/diag/contenttype.go +++ b/subcommands/diag/contenttype.go @@ -64,7 +64,7 @@ func (cmd *DiagContentType) Execute(ctx *appcontext.AppContext, repo *repository break } - fmt.Fprintln(ctx.Stdout, path) + fmt.Println(path) } if err := it.Err(); err != nil { return 1, err diff --git a/subcommands/diag/dirpack.go b/subcommands/diag/dirpack.go index 3824555b0..48efc6c4f 100644 --- a/subcommands/diag/dirpack.go +++ b/subcommands/diag/dirpack.go @@ -82,7 +82,7 @@ func (cmd *DiagDirPack) Execute(ctx *appcontext.AppContext, repo *repository.Rep break } - fmt.Fprintf(ctx.Stdout, "%s %x\n", path, dirpackmac) + fmt.Printf("%s %x\n", path, dirpackmac) obj, err := snap.LookupObject(dirpackmac) if err != nil { @@ -116,7 +116,7 @@ func (cmd *DiagDirPack) Execute(ctx *appcontext.AppContext, repo *repository.Rep return 1, fmt.Errorf("failed to read entry mac: %w", err) } - fmt.Fprintf(ctx.Stdout, "vfs-entry %x %s %v %v %s\n", entry.MAC, path, + fmt.Printf("vfs-entry %x %s %v %v %s\n", entry.MAC, path, siz, typ, entry.Name()) } } diff --git a/subcommands/diag/locks.go b/subcommands/diag/locks.go index 287cf886e..a62ea3001 100644 --- a/subcommands/diag/locks.go +++ b/subcommands/diag/locks.go @@ -3,6 +3,7 @@ package diag import ( "flag" "fmt" + "os" "time" "github.com/PlakarKorp/kloset/repository" @@ -32,13 +33,13 @@ func (cmd *DiagLocks) Execute(ctx *appcontext.AppContext, repo *repository.Repos for _, lockID := range locksID { rd, err := repo.GetLock(lockID) if err != nil { - fmt.Fprintf(ctx.Stderr, "Failed to fetch lock %x\n", lockID) + fmt.Fprintf(os.Stderr, "Failed to fetch lock %x\n", lockID) } lock, err := repository.NewLockFromStream(rd) rd.Close() if err != nil { - fmt.Fprintf(ctx.Stderr, "Failed to deserialize lock %x\n", lockID) + fmt.Fprintf(os.Stderr, "Failed to deserialize lock %x\n", lockID) } var lockType string @@ -48,7 +49,7 @@ func (cmd *DiagLocks) Execute(ctx *appcontext.AppContext, repo *repository.Repos lockType = "shared" } - fmt.Fprintf(ctx.Stdout, "[%x] Got %s access on %s owner %s\n", lockID, lockType, lock.Timestamp.UTC().Format(time.RFC3339), lock.Hostname) + fmt.Printf("[%x] Got %s access on %s owner %s\n", lockID, lockType, lock.Timestamp.UTC().Format(time.RFC3339), lock.Hostname) } return 0, nil diff --git a/subcommands/diag/object.go b/subcommands/diag/object.go index 24f934d8c..e6e525b1b 100644 --- a/subcommands/diag/object.go +++ b/subcommands/diag/object.go @@ -6,10 +6,10 @@ import ( "fmt" "io" - "github.com/PlakarKorp/plakar/appcontext" "github.com/PlakarKorp/kloset/objects" "github.com/PlakarKorp/kloset/repository" "github.com/PlakarKorp/kloset/resources" + "github.com/PlakarKorp/plakar/appcontext" "github.com/PlakarKorp/plakar/subcommands" ) @@ -62,11 +62,11 @@ func (cmd *DiagObject) Execute(ctx *appcontext.AppContext, repo *repository.Repo return 1, err } - fmt.Fprintf(ctx.Stdout, "object: %x\n", object.ContentMAC) - fmt.Fprintln(ctx.Stdout, " type:", object.ContentType) - fmt.Fprintln(ctx.Stdout, " chunks:") + fmt.Printf("object: %x\n", object.ContentMAC) + fmt.Println(" type:", object.ContentType) + fmt.Println(" chunks:") for _, chunk := range object.Chunks { - fmt.Fprintf(ctx.Stdout, " MAC: %x\n", chunk.ContentMAC) + fmt.Printf(" MAC: %x\n", chunk.ContentMAC) } return 0, nil } diff --git a/subcommands/diag/packfile.go b/subcommands/diag/packfile.go index e1cfae774..aea6c7a25 100644 --- a/subcommands/diag/packfile.go +++ b/subcommands/diag/packfile.go @@ -4,10 +4,11 @@ import ( "encoding/hex" "flag" "fmt" + "os" "time" - "github.com/PlakarKorp/plakar/appcontext" "github.com/PlakarKorp/kloset/repository" + "github.com/PlakarKorp/plakar/appcontext" "github.com/PlakarKorp/plakar/subcommands" ) @@ -35,7 +36,7 @@ func (cmd *DiagPackfile) Execute(ctx *appcontext.AppContext, repo *repository.Re } for _, packfile := range packfiles { - fmt.Fprintf(ctx.Stdout, "%x\n", packfile) + fmt.Printf("%x\n", packfile) } } else { for _, arg := range cmd.Args { @@ -58,13 +59,13 @@ func (cmd *DiagPackfile) Execute(ctx *appcontext.AppContext, repo *repository.Re return 1, err } - fmt.Fprintf(ctx.Stdout, "Version: %s\n", p.Footer.Version) - fmt.Fprintf(ctx.Stdout, "Timestamp: %s\n", time.Unix(0, p.Footer.Timestamp)) - fmt.Fprintf(ctx.Stdout, "Index MAC: %x\n", p.Footer.IndexMAC) - fmt.Fprintln(ctx.Stdout) + fmt.Printf("Version: %s\n", p.Footer.Version) + fmt.Printf("Timestamp: %s\n", time.Unix(0, p.Footer.Timestamp)) + fmt.Printf("Index MAC: %x\n", p.Footer.IndexMAC) + fmt.Fprintln(os.Stdout) for i, entry := range p.Index { - fmt.Fprintf(ctx.Stdout, "blob[%d]: %x %d %d %x %s\n", i, entry.MAC, entry.Offset, entry.Length, entry.Flags, entry.Type) + fmt.Printf("blob[%d]: %x %d %d %x %s\n", i, entry.MAC, entry.Offset, entry.Length, entry.Flags, entry.Type) } } } diff --git a/subcommands/diag/repository.go b/subcommands/diag/repository.go index fe33a96ef..918c62da5 100644 --- a/subcommands/diag/repository.go +++ b/subcommands/diag/repository.go @@ -43,61 +43,61 @@ func (cmd *DiagRepository) Parse(ctx *appcontext.AppContext, args []string) erro func (cmd *DiagRepository) Execute(ctx *appcontext.AppContext, repo *repository.Repository) (int, error) { - fmt.Fprintln(ctx.Stdout, "Version:", repo.Configuration().Version) - fmt.Fprintln(ctx.Stdout, "Timestamp:", repo.Configuration().Timestamp) - fmt.Fprintln(ctx.Stdout, "RepositoryID:", repo.Configuration().RepositoryID) + fmt.Println("Version:", repo.Configuration().Version) + fmt.Println("Timestamp:", repo.Configuration().Timestamp) + fmt.Println("RepositoryID:", repo.Configuration().RepositoryID) - fmt.Fprintln(ctx.Stdout, "Packfile:") - fmt.Fprintf(ctx.Stdout, " - MaxSize: %s (%d bytes)\n", + fmt.Println("Packfile:") + fmt.Printf(" - MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Packfile.MaxSize)), repo.Configuration().Packfile.MaxSize) - fmt.Fprintln(ctx.Stdout, "Chunking:") - fmt.Fprintln(ctx.Stdout, " - Algorithm:", repo.Configuration().Chunking.Algorithm) - fmt.Fprintf(ctx.Stdout, " - MinSize: %s (%d bytes)\n", + fmt.Println("Chunking:") + fmt.Println(" - Algorithm:", repo.Configuration().Chunking.Algorithm) + fmt.Printf(" - MinSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Chunking.MinSize)), repo.Configuration().Chunking.MinSize) - fmt.Fprintf(ctx.Stdout, " - NormalSize: %s (%d bytes)\n", + fmt.Printf(" - NormalSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Chunking.NormalSize)), repo.Configuration().Chunking.NormalSize) - fmt.Fprintf(ctx.Stdout, " - MaxSize: %s (%d bytes)\n", + fmt.Printf(" - MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Chunking.MaxSize)), repo.Configuration().Chunking.MaxSize) - fmt.Fprintln(ctx.Stdout, "Hashing:") - fmt.Fprintln(ctx.Stdout, " - Algorithm:", repo.Configuration().Hashing.Algorithm) - fmt.Fprintln(ctx.Stdout, " - Bits:", repo.Configuration().Hashing.Bits) + fmt.Println("Hashing:") + fmt.Println(" - Algorithm:", repo.Configuration().Hashing.Algorithm) + fmt.Println(" - Bits:", repo.Configuration().Hashing.Bits) if repo.Configuration().Compression != nil { - fmt.Fprintln(ctx.Stdout, "Compression:") - fmt.Fprintln(ctx.Stdout, " - Algorithm:", repo.Configuration().Compression.Algorithm) - fmt.Fprintln(ctx.Stdout, " - Level:", repo.Configuration().Compression.Level) + fmt.Println("Compression:") + fmt.Println(" - Algorithm:", repo.Configuration().Compression.Algorithm) + fmt.Println(" - Level:", repo.Configuration().Compression.Level) } if repo.Configuration().Encryption != nil { - fmt.Fprintln(ctx.Stdout, "Encryption:") - fmt.Fprintln(ctx.Stdout, " - Data Algorithm:", repo.Configuration().Encryption.DataAlgorithm) - fmt.Fprintln(ctx.Stdout, " - Subkey Algorithm:", repo.Configuration().Encryption.SubKeyAlgorithm) - fmt.Fprintf(ctx.Stdout, " - Canary: %x\n", repo.Configuration().Encryption.Canary) - fmt.Fprintln(ctx.Stdout, " - KDF:", repo.Configuration().Encryption.KDFParams.KDF) - fmt.Fprintf(ctx.Stdout, " - Salt: %x\n", repo.Configuration().Encryption.KDFParams.Salt) + fmt.Println("Encryption:") + fmt.Println(" - Data Algorithm:", repo.Configuration().Encryption.DataAlgorithm) + fmt.Println(" - Subkey Algorithm:", repo.Configuration().Encryption.SubKeyAlgorithm) + fmt.Printf(" - Canary: %x\n", repo.Configuration().Encryption.Canary) + fmt.Println(" - KDF:", repo.Configuration().Encryption.KDFParams.KDF) + fmt.Printf(" - Salt: %x\n", repo.Configuration().Encryption.KDFParams.Salt) switch repo.Configuration().Encryption.KDFParams.KDF { case "ARGON2ID": - fmt.Fprintf(ctx.Stdout, " - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.SaltSize) - fmt.Fprintf(ctx.Stdout, " - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.KeyLen) - fmt.Fprintf(ctx.Stdout, " - Time: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Time) - fmt.Fprintf(ctx.Stdout, " - Memory: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Memory) - fmt.Fprintf(ctx.Stdout, " - Thread: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Threads) + fmt.Printf(" - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.SaltSize) + fmt.Printf(" - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.KeyLen) + fmt.Printf(" - Time: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Time) + fmt.Printf(" - Memory: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Memory) + fmt.Printf(" - Thread: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Threads) case "SCRYPT": - fmt.Fprintf(ctx.Stdout, " - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.SaltSize) - fmt.Fprintf(ctx.Stdout, " - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.KeyLen) - fmt.Fprintf(ctx.Stdout, " - N: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.N) - fmt.Fprintf(ctx.Stdout, " - R: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.R) - fmt.Fprintf(ctx.Stdout, " - P: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.P) + fmt.Printf(" - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.SaltSize) + fmt.Printf(" - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.KeyLen) + fmt.Printf(" - N: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.N) + fmt.Printf(" - R: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.R) + fmt.Printf(" - P: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.P) case "PBKDF2": - fmt.Fprintf(ctx.Stdout, " - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.SaltSize) - fmt.Fprintf(ctx.Stdout, " - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.KeyLen) - fmt.Fprintf(ctx.Stdout, " - Iterations: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Iterations) - fmt.Fprintf(ctx.Stdout, " - Hashing: %s\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Hashing) + fmt.Printf(" - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.SaltSize) + fmt.Printf(" - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.KeyLen) + fmt.Printf(" - Iterations: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Iterations) + fmt.Printf(" - Hashing: %s\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Hashing) default: - fmt.Fprintf(ctx.Stdout, " - Unsupported KDF: %s\n", repo.Configuration().Encryption.KDFParams.KDF) + fmt.Printf(" - Unsupported KDF: %s\n", repo.Configuration().Encryption.KDFParams.KDF) } } @@ -106,7 +106,7 @@ func (cmd *DiagRepository) Execute(ctx *appcontext.AppContext, repo *repository. return 1, err } - fmt.Fprintln(ctx.Stdout, "Snapshots:", len(snapshotIDs)) + fmt.Println("Snapshots:", len(snapshotIDs)) totalSize := uint64(0) for _, snapshotID := range snapshotIDs { snap, err := snapshot.Load(repo, snapshotID) @@ -116,7 +116,7 @@ func (cmd *DiagRepository) Execute(ctx *appcontext.AppContext, repo *repository. totalSize += snap.Header.GetSource(0).Summary.Directory.Size + snap.Header.GetSource(0).Summary.Below.Size snap.Close() } - fmt.Fprintf(ctx.Stdout, "Size: %s (%d bytes)\n", humanize.IBytes(totalSize), totalSize) + fmt.Printf("Size: %s (%d bytes)\n", humanize.IBytes(totalSize), totalSize) return 0, nil } diff --git a/subcommands/diag/search.go b/subcommands/diag/search.go index abfa615a3..b8ec20757 100644 --- a/subcommands/diag/search.go +++ b/subcommands/diag/search.go @@ -65,7 +65,7 @@ func (cmd *DiagSearch) Execute(ctx *appcontext.AppContext, repo *repository.Repo if err != nil { return 1, err } - fmt.Fprintf(ctx.Stdout, "%x:%s\n", snap.Header.Identifier[0:4], entry.Path()) + fmt.Printf("%x:%s\n", snap.Header.Identifier[0:4], entry.Path()) } return 0, nil diff --git a/subcommands/diag/snapshot.go b/subcommands/diag/snapshot.go index 3e07c18fe..f34caf6fb 100644 --- a/subcommands/diag/snapshot.go +++ b/subcommands/diag/snapshot.go @@ -46,73 +46,73 @@ func (cmd *DiagSnapshot) Execute(ctx *appcontext.AppContext, repo *repository.Re header := snap.Header indexID := header.GetIndexID() - fmt.Fprintf(ctx.Stdout, "Version: %s\n", repo.Configuration().Version) - fmt.Fprintf(ctx.Stdout, "SnapshotID: %s\n", hex.EncodeToString(indexID[:])) - fmt.Fprintf(ctx.Stdout, "Timestamp: %s\n", header.Timestamp) - fmt.Fprintf(ctx.Stdout, "Duration: %s\n", header.Duration) - - fmt.Fprintf(ctx.Stdout, "Name: %s\n", header.Name) - fmt.Fprintf(ctx.Stdout, "Environment: %s\n", header.Environment) - fmt.Fprintf(ctx.Stdout, "Perimeter: %s\n", header.Perimeter) - fmt.Fprintf(ctx.Stdout, "Category: %s\n", header.Category) + fmt.Printf("Version: %s\n", repo.Configuration().Version) + fmt.Printf("SnapshotID: %s\n", hex.EncodeToString(indexID[:])) + fmt.Printf("Timestamp: %s\n", header.Timestamp) + fmt.Printf("Duration: %s\n", header.Duration) + + fmt.Printf("Name: %s\n", header.Name) + fmt.Printf("Environment: %s\n", header.Environment) + fmt.Printf("Perimeter: %s\n", header.Perimeter) + fmt.Printf("Category: %s\n", header.Category) if len(header.Tags) > 0 { - fmt.Fprintf(ctx.Stdout, "Tags: %s\n", strings.Join(header.Tags, ", ")) + fmt.Printf("Tags: %s\n", strings.Join(header.Tags, ", ")) } if header.Identity.Identifier != uuid.Nil { - fmt.Fprintln(ctx.Stdout, "Identity:") - fmt.Fprintf(ctx.Stdout, " - Identifier: %s\n", header.Identity.Identifier) - fmt.Fprintf(ctx.Stdout, " - PublicKey: %s\n", base64.RawStdEncoding.EncodeToString(header.Identity.PublicKey)) + fmt.Println("Identity:") + fmt.Printf(" - Identifier: %s\n", header.Identity.Identifier) + fmt.Printf(" - PublicKey: %s\n", base64.RawStdEncoding.EncodeToString(header.Identity.PublicKey)) } - fmt.Fprintf(ctx.Stdout, "VFS: %x\n", header.GetSource(0).VFS) - - fmt.Fprintln(ctx.Stdout, "Importer:") - fmt.Fprintf(ctx.Stdout, " - Type: %s\n", header.GetSource(0).Importer.Type) - fmt.Fprintf(ctx.Stdout, " - Origin: %s\n", header.GetSource(0).Importer.Origin) - fmt.Fprintf(ctx.Stdout, " - Directory: %s\n", header.GetSource(0).Importer.Directory) - - fmt.Fprintln(ctx.Stdout, "Context:") - fmt.Fprintf(ctx.Stdout, " - MachineID: %s\n", header.GetContext("MachineID")) - fmt.Fprintf(ctx.Stdout, " - Hostname: %s\n", header.GetContext("Hostname")) - fmt.Fprintf(ctx.Stdout, " - Username: %s\n", header.GetContext("Username")) - fmt.Fprintf(ctx.Stdout, " - OperatingSystem: %s\n", header.GetContext("OperatingSystem")) - fmt.Fprintf(ctx.Stdout, " - Architecture: %s\n", header.GetContext("Architecture")) - fmt.Fprintf(ctx.Stdout, " - NumCPU: %s\n", header.GetContext("NumCPU")) - fmt.Fprintf(ctx.Stdout, " - GOMAXPROCS: %s\n", header.GetContext("GOMAXPROCS")) - fmt.Fprintf(ctx.Stdout, " - ProcessID: %s\n", header.GetContext("ProcessID")) - fmt.Fprintf(ctx.Stdout, " - Client: %s\n", header.GetContext("Client")) - fmt.Fprintf(ctx.Stdout, " - CommandLine: %s\n", header.GetContext("CommandLine")) - - fmt.Fprintln(ctx.Stdout, "Summary:") - fmt.Fprintf(ctx.Stdout, " - Directories: %d\n", header.GetSource(0).Summary.Directory.Directories+header.GetSource(0).Summary.Below.Directories) - fmt.Fprintf(ctx.Stdout, " - Files: %d\n", header.GetSource(0).Summary.Directory.Files+header.GetSource(0).Summary.Below.Files) - fmt.Fprintf(ctx.Stdout, " - Symlinks: %d\n", header.GetSource(0).Summary.Directory.Symlinks+header.GetSource(0).Summary.Below.Symlinks) - fmt.Fprintf(ctx.Stdout, " - Devices: %d\n", header.GetSource(0).Summary.Directory.Devices+header.GetSource(0).Summary.Below.Devices) - fmt.Fprintf(ctx.Stdout, " - Pipes: %d\n", header.GetSource(0).Summary.Directory.Pipes+header.GetSource(0).Summary.Below.Pipes) - fmt.Fprintf(ctx.Stdout, " - Sockets: %d\n", header.GetSource(0).Summary.Directory.Sockets+header.GetSource(0).Summary.Below.Sockets) - fmt.Fprintf(ctx.Stdout, " - Setuid: %d\n", header.GetSource(0).Summary.Directory.Setuid+header.GetSource(0).Summary.Below.Setuid) - fmt.Fprintf(ctx.Stdout, " - Setgid: %d\n", header.GetSource(0).Summary.Directory.Setgid+header.GetSource(0).Summary.Below.Setgid) - fmt.Fprintf(ctx.Stdout, " - Sticky: %d\n", header.GetSource(0).Summary.Directory.Sticky+header.GetSource(0).Summary.Below.Sticky) - - fmt.Fprintf(ctx.Stdout, " - Objects: %d\n", header.GetSource(0).Summary.Directory.Objects+header.GetSource(0).Summary.Below.Objects) - fmt.Fprintf(ctx.Stdout, " - Chunks: %d\n", header.GetSource(0).Summary.Directory.Chunks+header.GetSource(0).Summary.Below.Chunks) - fmt.Fprintf(ctx.Stdout, " - MinSize: %s (%d bytes)\n", humanize.IBytes(min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)), min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)) - fmt.Fprintf(ctx.Stdout, " - MaxSize: %s (%d bytes)\n", humanize.IBytes(max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)), max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)) - fmt.Fprintf(ctx.Stdout, " - Size: %s (%d bytes)\n", humanize.IBytes(header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size), header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size) - fmt.Fprintf(ctx.Stdout, " - MinModTime: %s\n", time.Unix(min(header.GetSource(0).Summary.Directory.MinModTime, header.GetSource(0).Summary.Below.MinModTime), 0)) - fmt.Fprintf(ctx.Stdout, " - MaxModTime: %s\n", time.Unix(max(header.GetSource(0).Summary.Directory.MaxModTime, header.GetSource(0).Summary.Below.MaxModTime), 0)) - fmt.Fprintf(ctx.Stdout, " - MinEntropy: %f\n", min(header.GetSource(0).Summary.Directory.MinEntropy, header.GetSource(0).Summary.Below.MinEntropy)) - fmt.Fprintf(ctx.Stdout, " - MaxEntropy: %f\n", max(header.GetSource(0).Summary.Directory.MaxEntropy, header.GetSource(0).Summary.Below.MaxEntropy)) - fmt.Fprintf(ctx.Stdout, " - HiEntropy: %d\n", header.GetSource(0).Summary.Directory.HiEntropy+header.GetSource(0).Summary.Below.HiEntropy) - fmt.Fprintf(ctx.Stdout, " - LoEntropy: %d\n", header.GetSource(0).Summary.Directory.LoEntropy+header.GetSource(0).Summary.Below.LoEntropy) - fmt.Fprintf(ctx.Stdout, " - MIMEAudio: %d\n", header.GetSource(0).Summary.Directory.MIMEAudio+header.GetSource(0).Summary.Below.MIMEAudio) - fmt.Fprintf(ctx.Stdout, " - MIMEVideo: %d\n", header.GetSource(0).Summary.Directory.MIMEVideo+header.GetSource(0).Summary.Below.MIMEVideo) - fmt.Fprintf(ctx.Stdout, " - MIMEImage: %d\n", header.GetSource(0).Summary.Directory.MIMEImage+header.GetSource(0).Summary.Below.MIMEImage) - fmt.Fprintf(ctx.Stdout, " - MIMEText: %d\n", header.GetSource(0).Summary.Directory.MIMEText+header.GetSource(0).Summary.Below.MIMEText) - fmt.Fprintf(ctx.Stdout, " - MIMEApplication: %d\n", header.GetSource(0).Summary.Directory.MIMEApplication+header.GetSource(0).Summary.Below.MIMEApplication) - fmt.Fprintf(ctx.Stdout, " - MIMEOther: %d\n", header.GetSource(0).Summary.Directory.MIMEOther+header.GetSource(0).Summary.Below.MIMEOther) - - fmt.Fprintf(ctx.Stdout, " - Errors: %d\n", header.GetSource(0).Summary.Directory.Errors+header.GetSource(0).Summary.Below.Errors) + fmt.Printf("VFS: %x\n", header.GetSource(0).VFS) + + fmt.Println("Importer:") + fmt.Printf(" - Type: %s\n", header.GetSource(0).Importer.Type) + fmt.Printf(" - Origin: %s\n", header.GetSource(0).Importer.Origin) + fmt.Printf(" - Directory: %s\n", header.GetSource(0).Importer.Directory) + + fmt.Println("Context:") + fmt.Printf(" - MachineID: %s\n", header.GetContext("MachineID")) + fmt.Printf(" - Hostname: %s\n", header.GetContext("Hostname")) + fmt.Printf(" - Username: %s\n", header.GetContext("Username")) + fmt.Printf(" - OperatingSystem: %s\n", header.GetContext("OperatingSystem")) + fmt.Printf(" - Architecture: %s\n", header.GetContext("Architecture")) + fmt.Printf(" - NumCPU: %s\n", header.GetContext("NumCPU")) + fmt.Printf(" - GOMAXPROCS: %s\n", header.GetContext("GOMAXPROCS")) + fmt.Printf(" - ProcessID: %s\n", header.GetContext("ProcessID")) + fmt.Printf(" - Client: %s\n", header.GetContext("Client")) + fmt.Printf(" - CommandLine: %s\n", header.GetContext("CommandLine")) + + fmt.Println("Summary:") + fmt.Printf(" - Directories: %d\n", header.GetSource(0).Summary.Directory.Directories+header.GetSource(0).Summary.Below.Directories) + fmt.Printf(" - Files: %d\n", header.GetSource(0).Summary.Directory.Files+header.GetSource(0).Summary.Below.Files) + fmt.Printf(" - Symlinks: %d\n", header.GetSource(0).Summary.Directory.Symlinks+header.GetSource(0).Summary.Below.Symlinks) + fmt.Printf(" - Devices: %d\n", header.GetSource(0).Summary.Directory.Devices+header.GetSource(0).Summary.Below.Devices) + fmt.Printf(" - Pipes: %d\n", header.GetSource(0).Summary.Directory.Pipes+header.GetSource(0).Summary.Below.Pipes) + fmt.Printf(" - Sockets: %d\n", header.GetSource(0).Summary.Directory.Sockets+header.GetSource(0).Summary.Below.Sockets) + fmt.Printf(" - Setuid: %d\n", header.GetSource(0).Summary.Directory.Setuid+header.GetSource(0).Summary.Below.Setuid) + fmt.Printf(" - Setgid: %d\n", header.GetSource(0).Summary.Directory.Setgid+header.GetSource(0).Summary.Below.Setgid) + fmt.Printf(" - Sticky: %d\n", header.GetSource(0).Summary.Directory.Sticky+header.GetSource(0).Summary.Below.Sticky) + + fmt.Printf(" - Objects: %d\n", header.GetSource(0).Summary.Directory.Objects+header.GetSource(0).Summary.Below.Objects) + fmt.Printf(" - Chunks: %d\n", header.GetSource(0).Summary.Directory.Chunks+header.GetSource(0).Summary.Below.Chunks) + fmt.Printf(" - MinSize: %s (%d bytes)\n", humanize.IBytes(min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)), min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)) + fmt.Printf(" - MaxSize: %s (%d bytes)\n", humanize.IBytes(max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)), max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)) + fmt.Printf(" - Size: %s (%d bytes)\n", humanize.IBytes(header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size), header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size) + fmt.Printf(" - MinModTime: %s\n", time.Unix(min(header.GetSource(0).Summary.Directory.MinModTime, header.GetSource(0).Summary.Below.MinModTime), 0)) + fmt.Printf(" - MaxModTime: %s\n", time.Unix(max(header.GetSource(0).Summary.Directory.MaxModTime, header.GetSource(0).Summary.Below.MaxModTime), 0)) + fmt.Printf(" - MinEntropy: %f\n", min(header.GetSource(0).Summary.Directory.MinEntropy, header.GetSource(0).Summary.Below.MinEntropy)) + fmt.Printf(" - MaxEntropy: %f\n", max(header.GetSource(0).Summary.Directory.MaxEntropy, header.GetSource(0).Summary.Below.MaxEntropy)) + fmt.Printf(" - HiEntropy: %d\n", header.GetSource(0).Summary.Directory.HiEntropy+header.GetSource(0).Summary.Below.HiEntropy) + fmt.Printf(" - LoEntropy: %d\n", header.GetSource(0).Summary.Directory.LoEntropy+header.GetSource(0).Summary.Below.LoEntropy) + fmt.Printf(" - MIMEAudio: %d\n", header.GetSource(0).Summary.Directory.MIMEAudio+header.GetSource(0).Summary.Below.MIMEAudio) + fmt.Printf(" - MIMEVideo: %d\n", header.GetSource(0).Summary.Directory.MIMEVideo+header.GetSource(0).Summary.Below.MIMEVideo) + fmt.Printf(" - MIMEImage: %d\n", header.GetSource(0).Summary.Directory.MIMEImage+header.GetSource(0).Summary.Below.MIMEImage) + fmt.Printf(" - MIMEText: %d\n", header.GetSource(0).Summary.Directory.MIMEText+header.GetSource(0).Summary.Below.MIMEText) + fmt.Printf(" - MIMEApplication: %d\n", header.GetSource(0).Summary.Directory.MIMEApplication+header.GetSource(0).Summary.Below.MIMEApplication) + fmt.Printf(" - MIMEOther: %d\n", header.GetSource(0).Summary.Directory.MIMEOther+header.GetSource(0).Summary.Below.MIMEOther) + + fmt.Printf(" - Errors: %d\n", header.GetSource(0).Summary.Directory.Errors+header.GetSource(0).Summary.Below.Errors) return 0, nil } diff --git a/subcommands/diag/state.go b/subcommands/diag/state.go index 420ae50f7..ef302b09d 100644 --- a/subcommands/diag/state.go +++ b/subcommands/diag/state.go @@ -37,7 +37,7 @@ func (cmd *DiagState) Execute(ctx *appcontext.AppContext, repo *repository.Repos } for _, state := range states { - fmt.Fprintf(ctx.Stdout, "%x\n", state) + fmt.Printf("%x\n", state) } } else { for _, arg := range cmd.Args { @@ -74,16 +74,16 @@ func (cmd *DiagState) Execute(ctx *appcontext.AppContext, repo *repository.Repos return 1, err } - fmt.Fprintf(ctx.Stdout, "Version: %s\n", st.Metadata.Version) - fmt.Fprintf(ctx.Stdout, "Creation: %s\n", st.Metadata.Timestamp) - fmt.Fprintf(ctx.Stdout, "State serial: %s\n", st.Metadata.Serial) + fmt.Printf("Version: %s\n", st.Metadata.Version) + fmt.Printf("Creation: %s\n", st.Metadata.Timestamp) + fmt.Printf("State serial: %s\n", st.Metadata.Serial) printBlobs := func(name string, Type resources.Type) { for snapshot, err := range st.ListObjectsOfType(Type) { if err != nil { - fmt.Fprintf(ctx.Stdout, "Could not fetch blob entry for %s\n", name) + fmt.Printf("Could not fetch blob entry for %s\n", name) } else { - fmt.Fprintf(ctx.Stdout, "%s %x : packfile %x, offset %d, length %d\n", + fmt.Printf("%s %x : packfile %x, offset %d, length %d\n", name, snapshot.Blob, snapshot.Location.Packfile, @@ -95,9 +95,9 @@ func (cmd *DiagState) Execute(ctx *appcontext.AppContext, repo *repository.Repos printDeleted := func(name string, Type resources.Type) { for deletedEntry, err := range st.ListDeletedResources(Type) { if err != nil { - fmt.Fprintf(ctx.Stdout, "Could not fetch deleted blob entry for %s\n", name) + fmt.Printf("Could not fetch deleted blob entry for %s\n", name) } else { - fmt.Fprintf(ctx.Stdout, "deleted %s: %x, when=%s\n", + fmt.Printf("deleted %s: %x, when=%s\n", name, deletedEntry.Blob, deletedEntry.When) diff --git a/subcommands/diag/vfs.go b/subcommands/diag/vfs.go index fcb65356a..721b700c6 100644 --- a/subcommands/diag/vfs.go +++ b/subcommands/diag/vfs.go @@ -52,97 +52,97 @@ func (cmd *DiagVFS) Execute(ctx *appcontext.AppContext, repo *repository.Reposit } if entry.Stat().Mode().IsDir() { - fmt.Fprintf(ctx.Stdout, "[DirEntry]\n") + fmt.Printf("[DirEntry]\n") } else { - fmt.Fprintf(ctx.Stdout, "[FileEntry]\n") + fmt.Printf("[FileEntry]\n") } - fmt.Fprintf(ctx.Stdout, "Version: %d\n", entry.Version) - fmt.Fprintf(ctx.Stdout, "ParentPath: %s\n", entry.ParentPath) - fmt.Fprintf(ctx.Stdout, "Name: %s\n", entry.Stat().Name()) - fmt.Fprintf(ctx.Stdout, "Size: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Stat().Size())), entry.Stat().Size()) - fmt.Fprintf(ctx.Stdout, "Permissions: %s\n", entry.Stat().Mode()) - fmt.Fprintf(ctx.Stdout, "ModTime: %s\n", entry.Stat().ModTime()) - fmt.Fprintf(ctx.Stdout, "DeviceID: %d\n", entry.Stat().Dev()) - fmt.Fprintf(ctx.Stdout, "InodeID: %d\n", entry.Stat().Ino()) - fmt.Fprintf(ctx.Stdout, "UserID: %d\n", entry.Stat().Uid()) - fmt.Fprintf(ctx.Stdout, "GroupID: %d\n", entry.Stat().Gid()) - fmt.Fprintf(ctx.Stdout, "Username: %s\n", entry.Stat().Username()) - fmt.Fprintf(ctx.Stdout, "Groupname: %s\n", entry.Stat().Groupname()) - fmt.Fprintf(ctx.Stdout, "NumLinks: %d\n", entry.Stat().Nlink()) - fmt.Fprintf(ctx.Stdout, "ExtendedAttributes: %s\n", entry.ExtendedAttributes) - fmt.Fprintf(ctx.Stdout, "FileAttributes: %v\n", entry.FileAttributes) + fmt.Printf("Version: %d\n", entry.Version) + fmt.Printf("ParentPath: %s\n", entry.ParentPath) + fmt.Printf("Name: %s\n", entry.Stat().Name()) + fmt.Printf("Size: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Stat().Size())), entry.Stat().Size()) + fmt.Printf("Permissions: %s\n", entry.Stat().Mode()) + fmt.Printf("ModTime: %s\n", entry.Stat().ModTime()) + fmt.Printf("DeviceID: %d\n", entry.Stat().Dev()) + fmt.Printf("InodeID: %d\n", entry.Stat().Ino()) + fmt.Printf("UserID: %d\n", entry.Stat().Uid()) + fmt.Printf("GroupID: %d\n", entry.Stat().Gid()) + fmt.Printf("Username: %s\n", entry.Stat().Username()) + fmt.Printf("Groupname: %s\n", entry.Stat().Groupname()) + fmt.Printf("NumLinks: %d\n", entry.Stat().Nlink()) + fmt.Printf("ExtendedAttributes: %s\n", entry.ExtendedAttributes) + fmt.Printf("FileAttributes: %v\n", entry.FileAttributes) if entry.SymlinkTarget != "" { - fmt.Fprintf(ctx.Stdout, "SymlinkTarget: %s\n", entry.SymlinkTarget) + fmt.Printf("SymlinkTarget: %s\n", entry.SymlinkTarget) } - fmt.Fprintf(ctx.Stdout, "Classification:\n") + fmt.Printf("Classification:\n") for _, classification := range entry.Classifications { - fmt.Fprintf(ctx.Stdout, " - %s:\n", classification.Analyzer) + fmt.Printf(" - %s:\n", classification.Analyzer) for _, class := range classification.Classes { - fmt.Fprintf(ctx.Stdout, " - %s\n", class) + fmt.Printf(" - %s\n", class) } } - fmt.Fprintf(ctx.Stdout, "CustomMetadata: %s\n", entry.CustomMetadata) - fmt.Fprintf(ctx.Stdout, "Tags: %s\n", entry.Tags) - fmt.Fprintf(ctx.Stdout, "ExtendedAttributes: %v\n", entry.ExtendedAttributes) + fmt.Printf("CustomMetadata: %s\n", entry.CustomMetadata) + fmt.Printf("Tags: %s\n", entry.Tags) + fmt.Printf("ExtendedAttributes: %v\n", entry.ExtendedAttributes) if entry.Summary != nil { - fmt.Fprintf(ctx.Stdout, "Below.Directories: %d\n", entry.Summary.Below.Directories) - fmt.Fprintf(ctx.Stdout, "Below.Files: %d\n", entry.Summary.Below.Files) - fmt.Fprintf(ctx.Stdout, "Below.Symlinks: %d\n", entry.Summary.Below.Symlinks) - fmt.Fprintf(ctx.Stdout, "Below.Devices: %d\n", entry.Summary.Below.Devices) - fmt.Fprintf(ctx.Stdout, "Below.Pipes: %d\n", entry.Summary.Below.Pipes) - fmt.Fprintf(ctx.Stdout, "Below.Sockets: %d\n", entry.Summary.Below.Sockets) - fmt.Fprintf(ctx.Stdout, "Below.Setuid: %d\n", entry.Summary.Below.Setuid) - fmt.Fprintf(ctx.Stdout, "Below.Setgid: %d\n", entry.Summary.Below.Setgid) - fmt.Fprintf(ctx.Stdout, "Below.Sticky: %d\n", entry.Summary.Below.Sticky) - fmt.Fprintf(ctx.Stdout, "Below.Objects: %d\n", entry.Summary.Below.Objects) - fmt.Fprintf(ctx.Stdout, "Below.Chunks: %d\n", entry.Summary.Below.Chunks) - fmt.Fprintf(ctx.Stdout, "Below.MinSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Below.MinSize)), entry.Summary.Below.MinSize) - fmt.Fprintf(ctx.Stdout, "Below.MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Below.MaxSize)), entry.Summary.Below.MaxSize) - fmt.Fprintf(ctx.Stdout, "Below.Size: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Below.Size)), entry.Summary.Below.Size) - fmt.Fprintf(ctx.Stdout, "Below.MinModTime: %s\n", time.Unix(entry.Summary.Below.MinModTime, 0)) - fmt.Fprintf(ctx.Stdout, "Below.MaxModTime: %s\n", time.Unix(entry.Summary.Below.MaxModTime, 0)) - fmt.Fprintf(ctx.Stdout, "Below.MinEntropy: %f\n", entry.Summary.Below.MinEntropy) - fmt.Fprintf(ctx.Stdout, "Below.MaxEntropy: %f\n", entry.Summary.Below.MaxEntropy) - fmt.Fprintf(ctx.Stdout, "Below.HiEntropy: %d\n", entry.Summary.Below.HiEntropy) - fmt.Fprintf(ctx.Stdout, "Below.LoEntropy: %d\n", entry.Summary.Below.LoEntropy) - fmt.Fprintf(ctx.Stdout, "Below.MIMEAudio: %d\n", entry.Summary.Below.MIMEAudio) - fmt.Fprintf(ctx.Stdout, "Below.MIMEVideo: %d\n", entry.Summary.Below.MIMEVideo) - fmt.Fprintf(ctx.Stdout, "Below.MIMEImage: %d\n", entry.Summary.Below.MIMEImage) - fmt.Fprintf(ctx.Stdout, "Below.MIMEText: %d\n", entry.Summary.Below.MIMEText) - fmt.Fprintf(ctx.Stdout, "Below.MIMEApplication: %d\n", entry.Summary.Below.MIMEApplication) - fmt.Fprintf(ctx.Stdout, "Below.MIMEOther: %d\n", entry.Summary.Below.MIMEOther) - fmt.Fprintf(ctx.Stdout, "Below.Errors: %d\n", entry.Summary.Below.Errors) - fmt.Fprintf(ctx.Stdout, "Directory.Directories: %d\n", entry.Summary.Directory.Directories) - fmt.Fprintf(ctx.Stdout, "Directory.Files: %d\n", entry.Summary.Directory.Files) - fmt.Fprintf(ctx.Stdout, "Directory.Symlinks: %d\n", entry.Summary.Directory.Symlinks) - fmt.Fprintf(ctx.Stdout, "Directory.Devices: %d\n", entry.Summary.Directory.Devices) - fmt.Fprintf(ctx.Stdout, "Directory.Pipes: %d\n", entry.Summary.Directory.Pipes) - fmt.Fprintf(ctx.Stdout, "Directory.Sockets: %d\n", entry.Summary.Directory.Sockets) - fmt.Fprintf(ctx.Stdout, "Directory.Setuid: %d\n", entry.Summary.Directory.Setuid) - fmt.Fprintf(ctx.Stdout, "Directory.Setgid: %d\n", entry.Summary.Directory.Setgid) - fmt.Fprintf(ctx.Stdout, "Directory.Sticky: %d\n", entry.Summary.Directory.Sticky) - fmt.Fprintf(ctx.Stdout, "Directory.Objects: %d\n", entry.Summary.Directory.Objects) - fmt.Fprintf(ctx.Stdout, "Directory.Chunks: %d\n", entry.Summary.Directory.Chunks) - fmt.Fprintf(ctx.Stdout, "Directory.MinSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Directory.MinSize)), entry.Summary.Directory.MinSize) - fmt.Fprintf(ctx.Stdout, "Directory.MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Directory.MaxSize)), entry.Summary.Directory.MaxSize) - fmt.Fprintf(ctx.Stdout, "Directory.Size: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Directory.Size)), entry.Summary.Directory.Size) - fmt.Fprintf(ctx.Stdout, "Directory.MinModTime: %s\n", time.Unix(entry.Summary.Directory.MinModTime, 0)) - fmt.Fprintf(ctx.Stdout, "Directory.MaxModTime: %s\n", time.Unix(entry.Summary.Directory.MaxModTime, 0)) - fmt.Fprintf(ctx.Stdout, "Directory.MinEntropy: %f\n", entry.Summary.Directory.MinEntropy) - fmt.Fprintf(ctx.Stdout, "Directory.MaxEntropy: %f\n", entry.Summary.Directory.MaxEntropy) - fmt.Fprintf(ctx.Stdout, "Directory.AvgEntropy: %f\n", entry.Summary.Directory.AvgEntropy) - fmt.Fprintf(ctx.Stdout, "Directory.HiEntropy: %d\n", entry.Summary.Directory.HiEntropy) - fmt.Fprintf(ctx.Stdout, "Directory.LoEntropy: %d\n", entry.Summary.Directory.LoEntropy) - fmt.Fprintf(ctx.Stdout, "Directory.MIMEAudio: %d\n", entry.Summary.Directory.MIMEAudio) - fmt.Fprintf(ctx.Stdout, "Directory.MIMEVideo: %d\n", entry.Summary.Directory.MIMEVideo) - fmt.Fprintf(ctx.Stdout, "Directory.MIMEImage: %d\n", entry.Summary.Directory.MIMEImage) - fmt.Fprintf(ctx.Stdout, "Directory.MIMEText: %d\n", entry.Summary.Directory.MIMEText) - fmt.Fprintf(ctx.Stdout, "Directory.MIMEApplication: %d\n", entry.Summary.Directory.MIMEApplication) - fmt.Fprintf(ctx.Stdout, "Directory.MIMEOther: %d\n", entry.Summary.Directory.MIMEOther) - fmt.Fprintf(ctx.Stdout, "Directory.Errors: %d\n", entry.Summary.Directory.Errors) - fmt.Fprintf(ctx.Stdout, "Directory.Children: %d\n", entry.Summary.Directory.Children) + fmt.Printf("Below.Directories: %d\n", entry.Summary.Below.Directories) + fmt.Printf("Below.Files: %d\n", entry.Summary.Below.Files) + fmt.Printf("Below.Symlinks: %d\n", entry.Summary.Below.Symlinks) + fmt.Printf("Below.Devices: %d\n", entry.Summary.Below.Devices) + fmt.Printf("Below.Pipes: %d\n", entry.Summary.Below.Pipes) + fmt.Printf("Below.Sockets: %d\n", entry.Summary.Below.Sockets) + fmt.Printf("Below.Setuid: %d\n", entry.Summary.Below.Setuid) + fmt.Printf("Below.Setgid: %d\n", entry.Summary.Below.Setgid) + fmt.Printf("Below.Sticky: %d\n", entry.Summary.Below.Sticky) + fmt.Printf("Below.Objects: %d\n", entry.Summary.Below.Objects) + fmt.Printf("Below.Chunks: %d\n", entry.Summary.Below.Chunks) + fmt.Printf("Below.MinSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Below.MinSize)), entry.Summary.Below.MinSize) + fmt.Printf("Below.MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Below.MaxSize)), entry.Summary.Below.MaxSize) + fmt.Printf("Below.Size: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Below.Size)), entry.Summary.Below.Size) + fmt.Printf("Below.MinModTime: %s\n", time.Unix(entry.Summary.Below.MinModTime, 0)) + fmt.Printf("Below.MaxModTime: %s\n", time.Unix(entry.Summary.Below.MaxModTime, 0)) + fmt.Printf("Below.MinEntropy: %f\n", entry.Summary.Below.MinEntropy) + fmt.Printf("Below.MaxEntropy: %f\n", entry.Summary.Below.MaxEntropy) + fmt.Printf("Below.HiEntropy: %d\n", entry.Summary.Below.HiEntropy) + fmt.Printf("Below.LoEntropy: %d\n", entry.Summary.Below.LoEntropy) + fmt.Printf("Below.MIMEAudio: %d\n", entry.Summary.Below.MIMEAudio) + fmt.Printf("Below.MIMEVideo: %d\n", entry.Summary.Below.MIMEVideo) + fmt.Printf("Below.MIMEImage: %d\n", entry.Summary.Below.MIMEImage) + fmt.Printf("Below.MIMEText: %d\n", entry.Summary.Below.MIMEText) + fmt.Printf("Below.MIMEApplication: %d\n", entry.Summary.Below.MIMEApplication) + fmt.Printf("Below.MIMEOther: %d\n", entry.Summary.Below.MIMEOther) + fmt.Printf("Below.Errors: %d\n", entry.Summary.Below.Errors) + fmt.Printf("Directory.Directories: %d\n", entry.Summary.Directory.Directories) + fmt.Printf("Directory.Files: %d\n", entry.Summary.Directory.Files) + fmt.Printf("Directory.Symlinks: %d\n", entry.Summary.Directory.Symlinks) + fmt.Printf("Directory.Devices: %d\n", entry.Summary.Directory.Devices) + fmt.Printf("Directory.Pipes: %d\n", entry.Summary.Directory.Pipes) + fmt.Printf("Directory.Sockets: %d\n", entry.Summary.Directory.Sockets) + fmt.Printf("Directory.Setuid: %d\n", entry.Summary.Directory.Setuid) + fmt.Printf("Directory.Setgid: %d\n", entry.Summary.Directory.Setgid) + fmt.Printf("Directory.Sticky: %d\n", entry.Summary.Directory.Sticky) + fmt.Printf("Directory.Objects: %d\n", entry.Summary.Directory.Objects) + fmt.Printf("Directory.Chunks: %d\n", entry.Summary.Directory.Chunks) + fmt.Printf("Directory.MinSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Directory.MinSize)), entry.Summary.Directory.MinSize) + fmt.Printf("Directory.MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Directory.MaxSize)), entry.Summary.Directory.MaxSize) + fmt.Printf("Directory.Size: %s (%d bytes)\n", humanize.IBytes(uint64(entry.Summary.Directory.Size)), entry.Summary.Directory.Size) + fmt.Printf("Directory.MinModTime: %s\n", time.Unix(entry.Summary.Directory.MinModTime, 0)) + fmt.Printf("Directory.MaxModTime: %s\n", time.Unix(entry.Summary.Directory.MaxModTime, 0)) + fmt.Printf("Directory.MinEntropy: %f\n", entry.Summary.Directory.MinEntropy) + fmt.Printf("Directory.MaxEntropy: %f\n", entry.Summary.Directory.MaxEntropy) + fmt.Printf("Directory.AvgEntropy: %f\n", entry.Summary.Directory.AvgEntropy) + fmt.Printf("Directory.HiEntropy: %d\n", entry.Summary.Directory.HiEntropy) + fmt.Printf("Directory.LoEntropy: %d\n", entry.Summary.Directory.LoEntropy) + fmt.Printf("Directory.MIMEAudio: %d\n", entry.Summary.Directory.MIMEAudio) + fmt.Printf("Directory.MIMEVideo: %d\n", entry.Summary.Directory.MIMEVideo) + fmt.Printf("Directory.MIMEImage: %d\n", entry.Summary.Directory.MIMEImage) + fmt.Printf("Directory.MIMEText: %d\n", entry.Summary.Directory.MIMEText) + fmt.Printf("Directory.MIMEApplication: %d\n", entry.Summary.Directory.MIMEApplication) + fmt.Printf("Directory.MIMEOther: %d\n", entry.Summary.Directory.MIMEOther) + fmt.Printf("Directory.Errors: %d\n", entry.Summary.Directory.Errors) + fmt.Printf("Directory.Children: %d\n", entry.Summary.Directory.Children) } if entry.IsDir() { @@ -152,17 +152,17 @@ func (cmd *DiagVFS) Execute(ctx *appcontext.AppContext, repo *repository.Reposit } offset := 0 for child := range iter { - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Name(): %s\n", offset, child.Stat().Name()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Size(): %d\n", offset, child.Stat().Size()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Mode(): %s\n", offset, child.Stat().Mode()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Dev(): %d\n", offset, child.Stat().Dev()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Ino(): %d\n", offset, child.Stat().Ino()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Uid(): %d\n", offset, child.Stat().Uid()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Gid(): %d\n", offset, child.Stat().Gid()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Username(): %s\n", offset, child.Stat().Username()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Groupname(): %s\n", offset, child.Stat().Groupname()) - fmt.Fprintf(ctx.Stdout, "Child[%d].FileInfo.Nlink(): %d\n", offset, child.Stat().Nlink()) - fmt.Fprintf(ctx.Stdout, "Child[%d].ExtendedAttributes(): %v\n", offset, child.ExtendedAttributes) + fmt.Printf("Child[%d].FileInfo.Name(): %s\n", offset, child.Stat().Name()) + fmt.Printf("Child[%d].FileInfo.Size(): %d\n", offset, child.Stat().Size()) + fmt.Printf("Child[%d].FileInfo.Mode(): %s\n", offset, child.Stat().Mode()) + fmt.Printf("Child[%d].FileInfo.Dev(): %d\n", offset, child.Stat().Dev()) + fmt.Printf("Child[%d].FileInfo.Ino(): %d\n", offset, child.Stat().Ino()) + fmt.Printf("Child[%d].FileInfo.Uid(): %d\n", offset, child.Stat().Uid()) + fmt.Printf("Child[%d].FileInfo.Gid(): %d\n", offset, child.Stat().Gid()) + fmt.Printf("Child[%d].FileInfo.Username(): %s\n", offset, child.Stat().Username()) + fmt.Printf("Child[%d].FileInfo.Groupname(): %s\n", offset, child.Stat().Groupname()) + fmt.Printf("Child[%d].FileInfo.Nlink(): %d\n", offset, child.Stat().Nlink()) + fmt.Printf("Child[%d].ExtendedAttributes(): %v\n", offset, child.ExtendedAttributes) offset++ } } @@ -173,7 +173,7 @@ func (cmd *DiagVFS) Execute(ctx *appcontext.AppContext, repo *repository.Reposit } offset := 0 for err := range errors { - fmt.Fprintf(ctx.Stdout, "Error[%d]: %s: %s\n", offset, err.Name, err.Error) + fmt.Printf("Error[%d]: %s: %s\n", offset, err.Name, err.Error) offset++ } return 0, nil diff --git a/subcommands/diag/xattrs.go b/subcommands/diag/xattrs.go index e757cd355..106217728 100644 --- a/subcommands/diag/xattrs.go +++ b/subcommands/diag/xattrs.go @@ -87,7 +87,7 @@ func (cmd *DiagXattr) Execute(ctx *appcontext.AppContext, repo *repository.Repos return 1, err } - fmt.Fprintln(ctx.Stdout, xattr.Path, xattr.Name, string(value)) + fmt.Println(xattr.Path, xattr.Name, string(value)) } if err := it.Err(); err != nil { return 1, err diff --git a/subcommands/diff/diff.go b/subcommands/diff/diff.go index 45c80daf8..f08cc88b9 100644 --- a/subcommands/diff/diff.go +++ b/subcommands/diff/diff.go @@ -129,12 +129,12 @@ func (cmd *Diff) Execute(ctx *appcontext.AppContext, repo *repository.Repository } if cmd.Highlight { - err = quick.Highlight(ctx.Stdout, diff, "diff", "terminal", "dracula") + err = quick.Highlight(os.Stdout, diff, "diff", "terminal", "dracula") if err != nil { return 1, fmt.Errorf("diff: could not highlight diff: %w", err) } } else { - fmt.Fprintf(ctx.Stdout, "%s", diff) + fmt.Printf("%s", diff) } return 0, nil } diff --git a/subcommands/digest/digest.go b/subcommands/digest/digest.go index 59aed1f40..8f53f5cc9 100644 --- a/subcommands/digest/digest.go +++ b/subcommands/digest/digest.go @@ -134,6 +134,6 @@ func (cmd *Digest) displayDigests(ctx *appcontext.AppContext, fs *vfs.Filesystem return err } digest := hasher.Sum(nil) - fmt.Fprintf(ctx.Stdout, "%s (%s) = %x\n", algorithm, utils.SanitizeText(pathname), digest) + fmt.Printf("%s (%s) = %x\n", algorithm, utils.SanitizeText(pathname), digest) return nil } diff --git a/subcommands/info/errors.go b/subcommands/info/errors.go index 4f4fdb759..aef810f81 100644 --- a/subcommands/info/errors.go +++ b/subcommands/info/errors.go @@ -26,7 +26,7 @@ func (cmd *Info) executeErrors(ctx *appcontext.AppContext, repo *repository.Repo } for item := range errstream { - fmt.Fprintf(ctx.Stdout, "%s: %s\n", item.Name, item.Error) + fmt.Printf("%s: %s\n", item.Name, item.Error) } return 0, nil } diff --git a/subcommands/info/repository.go b/subcommands/info/repository.go index 3059203ab..1edcae03d 100644 --- a/subcommands/info/repository.go +++ b/subcommands/info/repository.go @@ -11,62 +11,62 @@ import ( func (cmd *Info) executeRepository(ctx *appcontext.AppContext, repo *repository.Repository) (int, error) { - fmt.Fprintln(ctx.Stdout, "Version:", repo.Configuration().Version) - fmt.Fprintln(ctx.Stdout, "Timestamp:", repo.Configuration().Timestamp) - fmt.Fprintln(ctx.Stdout, "RepositoryID:", repo.Configuration().RepositoryID) + fmt.Println("Version:", repo.Configuration().Version) + fmt.Println("Timestamp:", repo.Configuration().Timestamp) + fmt.Println("RepositoryID:", repo.Configuration().RepositoryID) - fmt.Fprintln(ctx.Stdout, "Packfile:") - fmt.Fprintf(ctx.Stdout, " - MaxSize: %s (%d bytes)\n", + fmt.Println("Packfile:") + fmt.Printf(" - MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Packfile.MaxSize)), repo.Configuration().Packfile.MaxSize) - fmt.Fprintln(ctx.Stdout, "Chunking:") - fmt.Fprintln(ctx.Stdout, " - Algorithm:", repo.Configuration().Chunking.Algorithm) - fmt.Fprintf(ctx.Stdout, " - MinSize: %s (%d bytes)\n", + fmt.Println("Chunking:") + fmt.Println(" - Algorithm:", repo.Configuration().Chunking.Algorithm) + fmt.Printf(" - MinSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Chunking.MinSize)), repo.Configuration().Chunking.MinSize) - fmt.Fprintf(ctx.Stdout, " - NormalSize: %s (%d bytes)\n", + fmt.Printf(" - NormalSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Chunking.NormalSize)), repo.Configuration().Chunking.NormalSize) - fmt.Fprintf(ctx.Stdout, " - MaxSize: %s (%d bytes)\n", + fmt.Printf(" - MaxSize: %s (%d bytes)\n", humanize.IBytes(uint64(repo.Configuration().Chunking.MaxSize)), repo.Configuration().Chunking.MaxSize) - fmt.Fprintln(ctx.Stdout, "Hashing:") - fmt.Fprintln(ctx.Stdout, " - Algorithm:", repo.Configuration().Hashing.Algorithm) - fmt.Fprintln(ctx.Stdout, " - Bits:", repo.Configuration().Hashing.Bits) + fmt.Println("Hashing:") + fmt.Println(" - Algorithm:", repo.Configuration().Hashing.Algorithm) + fmt.Println(" - Bits:", repo.Configuration().Hashing.Bits) if repo.Configuration().Compression != nil { - fmt.Fprintln(ctx.Stdout, "Compression:") - fmt.Fprintln(ctx.Stdout, " - Algorithm:", repo.Configuration().Compression.Algorithm) - fmt.Fprintln(ctx.Stdout, " - Level:", repo.Configuration().Compression.Level) + fmt.Println("Compression:") + fmt.Println(" - Algorithm:", repo.Configuration().Compression.Algorithm) + fmt.Println(" - Level:", repo.Configuration().Compression.Level) } if repo.Configuration().Encryption != nil { - fmt.Fprintln(ctx.Stdout, "Encryption:") - fmt.Fprintln(ctx.Stdout, " - SubkeyAlgorithm:", repo.Configuration().Encryption.SubKeyAlgorithm) - fmt.Fprintln(ctx.Stdout, " - DataAlgorithm:", repo.Configuration().Encryption.DataAlgorithm) - fmt.Fprintln(ctx.Stdout, " - ChunkSize:", repo.Configuration().Encryption.ChunkSize) - fmt.Fprintf(ctx.Stdout, " - Canary: %x\n", repo.Configuration().Encryption.Canary) - fmt.Fprintln(ctx.Stdout, " - KDF:", repo.Configuration().Encryption.KDFParams.KDF) - fmt.Fprintf(ctx.Stdout, " - Salt: %x\n", repo.Configuration().Encryption.KDFParams.Salt) + fmt.Println("Encryption:") + fmt.Println(" - SubkeyAlgorithm:", repo.Configuration().Encryption.SubKeyAlgorithm) + fmt.Println(" - DataAlgorithm:", repo.Configuration().Encryption.DataAlgorithm) + fmt.Println(" - ChunkSize:", repo.Configuration().Encryption.ChunkSize) + fmt.Printf(" - Canary: %x\n", repo.Configuration().Encryption.Canary) + fmt.Println(" - KDF:", repo.Configuration().Encryption.KDFParams.KDF) + fmt.Printf(" - Salt: %x\n", repo.Configuration().Encryption.KDFParams.Salt) switch repo.Configuration().Encryption.KDFParams.KDF { case "ARGON2ID": - fmt.Fprintf(ctx.Stdout, " - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.SaltSize) - fmt.Fprintf(ctx.Stdout, " - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.KeyLen) - fmt.Fprintf(ctx.Stdout, " - Time: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Time) - fmt.Fprintf(ctx.Stdout, " - Memory: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Memory) - fmt.Fprintf(ctx.Stdout, " - Thread: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Threads) + fmt.Printf(" - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.SaltSize) + fmt.Printf(" - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.KeyLen) + fmt.Printf(" - Time: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Time) + fmt.Printf(" - Memory: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Memory) + fmt.Printf(" - Thread: %d\n", repo.Configuration().Encryption.KDFParams.Argon2idParams.Threads) case "SCRYPT": - fmt.Fprintf(ctx.Stdout, " - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.SaltSize) - fmt.Fprintf(ctx.Stdout, " - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.KeyLen) - fmt.Fprintf(ctx.Stdout, " - N: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.N) - fmt.Fprintf(ctx.Stdout, " - R: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.R) - fmt.Fprintf(ctx.Stdout, " - P: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.P) + fmt.Printf(" - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.SaltSize) + fmt.Printf(" - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.KeyLen) + fmt.Printf(" - N: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.N) + fmt.Printf(" - R: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.R) + fmt.Printf(" - P: %d\n", repo.Configuration().Encryption.KDFParams.ScryptParams.P) case "PBKDF2": - fmt.Fprintf(ctx.Stdout, " - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.SaltSize) - fmt.Fprintf(ctx.Stdout, " - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.KeyLen) - fmt.Fprintf(ctx.Stdout, " - Iterations: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Iterations) - fmt.Fprintf(ctx.Stdout, " - Hashing: %s\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Hashing) + fmt.Printf(" - SaltSize: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.SaltSize) + fmt.Printf(" - KeyLen: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.KeyLen) + fmt.Printf(" - Iterations: %d\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Iterations) + fmt.Printf(" - Hashing: %s\n", repo.Configuration().Encryption.KDFParams.Pbkdf2Params.Hashing) default: - fmt.Fprintf(ctx.Stdout, " - Unsupported KDF: %s\n", repo.Configuration().Encryption.KDFParams.KDF) + fmt.Printf(" - Unsupported KDF: %s\n", repo.Configuration().Encryption.KDFParams.KDF) } } @@ -75,15 +75,15 @@ func (cmd *Info) executeRepository(ctx *appcontext.AppContext, repo *repository. return 1, fmt.Errorf("unable to calculate logical size: %w", err) } - fmt.Fprintln(ctx.Stdout, "Snapshots:", nSnapshots) + fmt.Println("Snapshots:", nSnapshots) storageSize, err := repo.Store().Size(ctx) if err != nil { return 1, fmt.Errorf("unable to compute storage size: %w", err) } - fmt.Fprintf(ctx.Stdout, "Storage size: %s (%d bytes)\n", humanize.IBytes(uint64(storageSize)), uint64(storageSize)) - fmt.Fprintf(ctx.Stdout, "Logical size: %s (%d bytes)\n", humanize.IBytes(uint64(logicalSize)), logicalSize) + fmt.Printf("Storage size: %s (%d bytes)\n", humanize.IBytes(uint64(storageSize)), uint64(storageSize)) + fmt.Printf("Logical size: %s (%d bytes)\n", humanize.IBytes(uint64(logicalSize)), logicalSize) return 0, nil } diff --git a/subcommands/info/snapshot.go b/subcommands/info/snapshot.go index ae0ae2db0..19b381b84 100644 --- a/subcommands/info/snapshot.go +++ b/subcommands/info/snapshot.go @@ -24,73 +24,73 @@ func (cmd *Info) executeSnapshot(ctx *appcontext.AppContext, repo *repository.Re header := snap.Header indexID := header.GetIndexID() - fmt.Fprintf(ctx.Stdout, "Version: %s\n", repo.Configuration().Version) - fmt.Fprintf(ctx.Stdout, "SnapshotID: %s\n", hex.EncodeToString(indexID[:])) - fmt.Fprintf(ctx.Stdout, "Timestamp: %s\n", header.Timestamp) - fmt.Fprintf(ctx.Stdout, "Duration: %s\n", header.Duration) + fmt.Printf("Version: %s\n", repo.Configuration().Version) + fmt.Printf("SnapshotID: %s\n", hex.EncodeToString(indexID[:])) + fmt.Printf("Timestamp: %s\n", header.Timestamp) + fmt.Printf("Duration: %s\n", header.Duration) - fmt.Fprintf(ctx.Stdout, "Name: %s\n", header.Name) - fmt.Fprintf(ctx.Stdout, "Environment: %s\n", header.Environment) - fmt.Fprintf(ctx.Stdout, "Perimeter: %s\n", header.Perimeter) - fmt.Fprintf(ctx.Stdout, "Category: %s\n", header.Category) + fmt.Printf("Name: %s\n", header.Name) + fmt.Printf("Environment: %s\n", header.Environment) + fmt.Printf("Perimeter: %s\n", header.Perimeter) + fmt.Printf("Category: %s\n", header.Category) if len(header.Tags) > 0 { - fmt.Fprintf(ctx.Stdout, "Tags: %s\n", strings.Join(header.Tags, ", ")) + fmt.Printf("Tags: %s\n", strings.Join(header.Tags, ", ")) } if header.Identity.Identifier != uuid.Nil { - fmt.Fprintln(ctx.Stdout, "Identity:") - fmt.Fprintf(ctx.Stdout, " - Identifier: %s\n", header.Identity.Identifier) - fmt.Fprintf(ctx.Stdout, " - PublicKey: %s\n", base64.RawStdEncoding.EncodeToString(header.Identity.PublicKey)) + fmt.Println("Identity:") + fmt.Printf(" - Identifier: %s\n", header.Identity.Identifier) + fmt.Printf(" - PublicKey: %s\n", base64.RawStdEncoding.EncodeToString(header.Identity.PublicKey)) } - fmt.Fprintf(ctx.Stdout, "VFS: %x\n", header.GetSource(0).VFS) + fmt.Printf("VFS: %x\n", header.GetSource(0).VFS) - fmt.Fprintln(ctx.Stdout, "Importer:") - fmt.Fprintf(ctx.Stdout, " - Type: %s\n", header.GetSource(0).Importer.Type) - fmt.Fprintf(ctx.Stdout, " - Origin: %s\n", header.GetSource(0).Importer.Origin) - fmt.Fprintf(ctx.Stdout, " - Directory: %s\n", header.GetSource(0).Importer.Directory) + fmt.Println("Importer:") + fmt.Printf(" - Type: %s\n", header.GetSource(0).Importer.Type) + fmt.Printf(" - Origin: %s\n", header.GetSource(0).Importer.Origin) + fmt.Printf(" - Directory: %s\n", header.GetSource(0).Importer.Directory) - fmt.Fprintln(ctx.Stdout, "Context:") - fmt.Fprintf(ctx.Stdout, " - MachineID: %s\n", header.GetContext("MachineID")) - fmt.Fprintf(ctx.Stdout, " - Hostname: %s\n", header.GetContext("Hostname")) - fmt.Fprintf(ctx.Stdout, " - Username: %s\n", header.GetContext("Username")) - fmt.Fprintf(ctx.Stdout, " - OperatingSystem: %s\n", header.GetContext("OperatingSystem")) - fmt.Fprintf(ctx.Stdout, " - Architecture: %s\n", header.GetContext("Architecture")) - fmt.Fprintf(ctx.Stdout, " - NumCPU: %s\n", header.GetContext("NumCPU")) - fmt.Fprintf(ctx.Stdout, " - GOMAXPROCS: %s\n", header.GetContext("GOMAXPROCS")) - fmt.Fprintf(ctx.Stdout, " - ProcessID: %s\n", header.GetContext("ProcessID")) - fmt.Fprintf(ctx.Stdout, " - Client: %s\n", header.GetContext("Client")) - fmt.Fprintf(ctx.Stdout, " - CommandLine: %s\n", header.GetContext("CommandLine")) + fmt.Println("Context:") + fmt.Printf(" - MachineID: %s\n", header.GetContext("MachineID")) + fmt.Printf(" - Hostname: %s\n", header.GetContext("Hostname")) + fmt.Printf(" - Username: %s\n", header.GetContext("Username")) + fmt.Printf(" - OperatingSystem: %s\n", header.GetContext("OperatingSystem")) + fmt.Printf(" - Architecture: %s\n", header.GetContext("Architecture")) + fmt.Printf(" - NumCPU: %s\n", header.GetContext("NumCPU")) + fmt.Printf(" - GOMAXPROCS: %s\n", header.GetContext("GOMAXPROCS")) + fmt.Printf(" - ProcessID: %s\n", header.GetContext("ProcessID")) + fmt.Printf(" - Client: %s\n", header.GetContext("Client")) + fmt.Printf(" - CommandLine: %s\n", header.GetContext("CommandLine")) - fmt.Fprintln(ctx.Stdout, "Summary:") - fmt.Fprintf(ctx.Stdout, " - Directories: %d\n", header.GetSource(0).Summary.Directory.Directories+header.GetSource(0).Summary.Below.Directories) - fmt.Fprintf(ctx.Stdout, " - Files: %d\n", header.GetSource(0).Summary.Directory.Files+header.GetSource(0).Summary.Below.Files) - fmt.Fprintf(ctx.Stdout, " - Symlinks: %d\n", header.GetSource(0).Summary.Directory.Symlinks+header.GetSource(0).Summary.Below.Symlinks) - fmt.Fprintf(ctx.Stdout, " - Devices: %d\n", header.GetSource(0).Summary.Directory.Devices+header.GetSource(0).Summary.Below.Devices) - fmt.Fprintf(ctx.Stdout, " - Pipes: %d\n", header.GetSource(0).Summary.Directory.Pipes+header.GetSource(0).Summary.Below.Pipes) - fmt.Fprintf(ctx.Stdout, " - Sockets: %d\n", header.GetSource(0).Summary.Directory.Sockets+header.GetSource(0).Summary.Below.Sockets) - fmt.Fprintf(ctx.Stdout, " - Setuid: %d\n", header.GetSource(0).Summary.Directory.Setuid+header.GetSource(0).Summary.Below.Setuid) - fmt.Fprintf(ctx.Stdout, " - Setgid: %d\n", header.GetSource(0).Summary.Directory.Setgid+header.GetSource(0).Summary.Below.Setgid) - fmt.Fprintf(ctx.Stdout, " - Sticky: %d\n", header.GetSource(0).Summary.Directory.Sticky+header.GetSource(0).Summary.Below.Sticky) + fmt.Println("Summary:") + fmt.Printf(" - Directories: %d\n", header.GetSource(0).Summary.Directory.Directories+header.GetSource(0).Summary.Below.Directories) + fmt.Printf(" - Files: %d\n", header.GetSource(0).Summary.Directory.Files+header.GetSource(0).Summary.Below.Files) + fmt.Printf(" - Symlinks: %d\n", header.GetSource(0).Summary.Directory.Symlinks+header.GetSource(0).Summary.Below.Symlinks) + fmt.Printf(" - Devices: %d\n", header.GetSource(0).Summary.Directory.Devices+header.GetSource(0).Summary.Below.Devices) + fmt.Printf(" - Pipes: %d\n", header.GetSource(0).Summary.Directory.Pipes+header.GetSource(0).Summary.Below.Pipes) + fmt.Printf(" - Sockets: %d\n", header.GetSource(0).Summary.Directory.Sockets+header.GetSource(0).Summary.Below.Sockets) + fmt.Printf(" - Setuid: %d\n", header.GetSource(0).Summary.Directory.Setuid+header.GetSource(0).Summary.Below.Setuid) + fmt.Printf(" - Setgid: %d\n", header.GetSource(0).Summary.Directory.Setgid+header.GetSource(0).Summary.Below.Setgid) + fmt.Printf(" - Sticky: %d\n", header.GetSource(0).Summary.Directory.Sticky+header.GetSource(0).Summary.Below.Sticky) - fmt.Fprintf(ctx.Stdout, " - Objects: %d\n", header.GetSource(0).Summary.Directory.Objects+header.GetSource(0).Summary.Below.Objects) - fmt.Fprintf(ctx.Stdout, " - Chunks: %d\n", header.GetSource(0).Summary.Directory.Chunks+header.GetSource(0).Summary.Below.Chunks) - fmt.Fprintf(ctx.Stdout, " - MinSize: %s (%d bytes)\n", humanize.IBytes(min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)), min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)) - fmt.Fprintf(ctx.Stdout, " - MaxSize: %s (%d bytes)\n", humanize.IBytes(max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)), max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)) - fmt.Fprintf(ctx.Stdout, " - Size: %s (%d bytes)\n", humanize.IBytes(header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size), header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size) - fmt.Fprintf(ctx.Stdout, " - MinModTime: %s\n", time.Unix(min(header.GetSource(0).Summary.Directory.MinModTime, header.GetSource(0).Summary.Below.MinModTime), 0)) - fmt.Fprintf(ctx.Stdout, " - MaxModTime: %s\n", time.Unix(max(header.GetSource(0).Summary.Directory.MaxModTime, header.GetSource(0).Summary.Below.MaxModTime), 0)) - fmt.Fprintf(ctx.Stdout, " - MinEntropy: %f\n", min(header.GetSource(0).Summary.Directory.MinEntropy, header.GetSource(0).Summary.Below.MinEntropy)) - fmt.Fprintf(ctx.Stdout, " - MaxEntropy: %f\n", max(header.GetSource(0).Summary.Directory.MaxEntropy, header.GetSource(0).Summary.Below.MaxEntropy)) - fmt.Fprintf(ctx.Stdout, " - HiEntropy: %d\n", header.GetSource(0).Summary.Directory.HiEntropy+header.GetSource(0).Summary.Below.HiEntropy) - fmt.Fprintf(ctx.Stdout, " - LoEntropy: %d\n", header.GetSource(0).Summary.Directory.LoEntropy+header.GetSource(0).Summary.Below.LoEntropy) - fmt.Fprintf(ctx.Stdout, " - MIMEAudio: %d\n", header.GetSource(0).Summary.Directory.MIMEAudio+header.GetSource(0).Summary.Below.MIMEAudio) - fmt.Fprintf(ctx.Stdout, " - MIMEVideo: %d\n", header.GetSource(0).Summary.Directory.MIMEVideo+header.GetSource(0).Summary.Below.MIMEVideo) - fmt.Fprintf(ctx.Stdout, " - MIMEImage: %d\n", header.GetSource(0).Summary.Directory.MIMEImage+header.GetSource(0).Summary.Below.MIMEImage) - fmt.Fprintf(ctx.Stdout, " - MIMEText: %d\n", header.GetSource(0).Summary.Directory.MIMEText+header.GetSource(0).Summary.Below.MIMEText) - fmt.Fprintf(ctx.Stdout, " - MIMEApplication: %d\n", header.GetSource(0).Summary.Directory.MIMEApplication+header.GetSource(0).Summary.Below.MIMEApplication) - fmt.Fprintf(ctx.Stdout, " - MIMEOther: %d\n", header.GetSource(0).Summary.Directory.MIMEOther+header.GetSource(0).Summary.Below.MIMEOther) + fmt.Printf(" - Objects: %d\n", header.GetSource(0).Summary.Directory.Objects+header.GetSource(0).Summary.Below.Objects) + fmt.Printf(" - Chunks: %d\n", header.GetSource(0).Summary.Directory.Chunks+header.GetSource(0).Summary.Below.Chunks) + fmt.Printf(" - MinSize: %s (%d bytes)\n", humanize.IBytes(min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)), min(header.GetSource(0).Summary.Directory.MinSize, header.GetSource(0).Summary.Below.MinSize)) + fmt.Printf(" - MaxSize: %s (%d bytes)\n", humanize.IBytes(max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)), max(header.GetSource(0).Summary.Directory.MaxSize, header.GetSource(0).Summary.Below.MaxSize)) + fmt.Printf(" - Size: %s (%d bytes)\n", humanize.IBytes(header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size), header.GetSource(0).Summary.Directory.Size+header.GetSource(0).Summary.Below.Size) + fmt.Printf(" - MinModTime: %s\n", time.Unix(min(header.GetSource(0).Summary.Directory.MinModTime, header.GetSource(0).Summary.Below.MinModTime), 0)) + fmt.Printf(" - MaxModTime: %s\n", time.Unix(max(header.GetSource(0).Summary.Directory.MaxModTime, header.GetSource(0).Summary.Below.MaxModTime), 0)) + fmt.Printf(" - MinEntropy: %f\n", min(header.GetSource(0).Summary.Directory.MinEntropy, header.GetSource(0).Summary.Below.MinEntropy)) + fmt.Printf(" - MaxEntropy: %f\n", max(header.GetSource(0).Summary.Directory.MaxEntropy, header.GetSource(0).Summary.Below.MaxEntropy)) + fmt.Printf(" - HiEntropy: %d\n", header.GetSource(0).Summary.Directory.HiEntropy+header.GetSource(0).Summary.Below.HiEntropy) + fmt.Printf(" - LoEntropy: %d\n", header.GetSource(0).Summary.Directory.LoEntropy+header.GetSource(0).Summary.Below.LoEntropy) + fmt.Printf(" - MIMEAudio: %d\n", header.GetSource(0).Summary.Directory.MIMEAudio+header.GetSource(0).Summary.Below.MIMEAudio) + fmt.Printf(" - MIMEVideo: %d\n", header.GetSource(0).Summary.Directory.MIMEVideo+header.GetSource(0).Summary.Below.MIMEVideo) + fmt.Printf(" - MIMEImage: %d\n", header.GetSource(0).Summary.Directory.MIMEImage+header.GetSource(0).Summary.Below.MIMEImage) + fmt.Printf(" - MIMEText: %d\n", header.GetSource(0).Summary.Directory.MIMEText+header.GetSource(0).Summary.Below.MIMEText) + fmt.Printf(" - MIMEApplication: %d\n", header.GetSource(0).Summary.Directory.MIMEApplication+header.GetSource(0).Summary.Below.MIMEApplication) + fmt.Printf(" - MIMEOther: %d\n", header.GetSource(0).Summary.Directory.MIMEOther+header.GetSource(0).Summary.Below.MIMEOther) - fmt.Fprintf(ctx.Stdout, " - Errors: %d\n", header.GetSource(0).Summary.Directory.Errors+header.GetSource(0).Summary.Below.Errors) + fmt.Printf(" - Errors: %d\n", header.GetSource(0).Summary.Directory.Errors+header.GetSource(0).Summary.Below.Errors) return 0, nil } diff --git a/subcommands/locate/locate.go b/subcommands/locate/locate.go index 3ac28c9f6..d9c8fa164 100644 --- a/subcommands/locate/locate.go +++ b/subcommands/locate/locate.go @@ -115,7 +115,7 @@ func (cmd *Locate) Execute(ctx *appcontext.AppContext, repo *repository.Reposito continue } } - fmt.Fprintf(ctx.Stdout, "%x:%s\n", snap.Header.Identifier[0:4], utils.SanitizeText(pathname)) + fmt.Printf("%x:%s\n", snap.Header.Identifier[0:4], utils.SanitizeText(pathname)) } } snap.Close() diff --git a/subcommands/login/login.go b/subcommands/login/login.go index b700e9882..96a7dc7e4 100644 --- a/subcommands/login/login.go +++ b/subcommands/login/login.go @@ -98,7 +98,7 @@ func (cmd *Login) Execute(ctx *appcontext.AppContext, repo *repository.Repositor if token != "" { status = "logged in" } - fmt.Fprintf(ctx.Stdout, "%s\n", status) + fmt.Printf("%s\n", status) return 0, nil } diff --git a/subcommands/login/token-create.go b/subcommands/login/token-create.go index e1842c9bf..a06779272 100644 --- a/subcommands/login/token-create.go +++ b/subcommands/login/token-create.go @@ -49,6 +49,6 @@ func (cmd *TokenCreate) Execute(ctx *appcontext.AppContext, repo *repository.Rep return 1, err } - fmt.Fprintln(ctx.Stdout, token) + fmt.Println(token) return 0, nil } diff --git a/subcommands/ls/ls.go b/subcommands/ls/ls.go index e0c0c3c2a..bd2857733 100644 --- a/subcommands/ls/ls.go +++ b/subcommands/ls/ls.go @@ -116,7 +116,7 @@ func (cmd *Ls) list_snapshots(ctx *appcontext.AppContext, repo *repository.Repos } if !cmd.DisplayUUID { - fmt.Fprintf(ctx.Stdout, "%s %10s%10s%10s %s%s\n", + fmt.Printf("%s %10s%10s%10s %s%s\n", snap.Header.Timestamp.UTC().Format(time.RFC3339), hex.EncodeToString(snap.Header.GetIndexShortID()), humanize.IBytes(snap.Header.GetSource(0).Summary.Directory.Size+snap.Header.GetSource(0).Summary.Below.Size), @@ -125,7 +125,7 @@ func (cmd *Ls) list_snapshots(ctx *appcontext.AppContext, repo *repository.Repos tags) } else { indexID := snap.Header.GetIndexID() - fmt.Fprintf(ctx.Stdout, "%s %3s%10s%10s %s%s\n", + fmt.Printf("%s %3s%10s%10s %s%s\n", snap.Header.Timestamp.UTC().Format(time.RFC3339), hex.EncodeToString(indexID[:]), humanize.IBytes(snap.Header.GetSource(0).Summary.Directory.Size+snap.Header.GetSource(0).Summary.Below.Size), @@ -201,7 +201,7 @@ func (cmd *Ls) list_snapshot(ctx *appcontext.AppContext, repo *repository.Reposi linkTarget = fmt.Sprintf(" -> %s", utils.SanitizeText(d.SymlinkTarget)) } - fmt.Fprintf(ctx.Stdout, "%s %s % 8s % 8s % 8s %s%s\n", + fmt.Printf("%s %s % 8s % 8s % 8s %s%s\n", sb.ModTime().UTC().Format(time.RFC3339), sb.Mode(), username, diff --git a/subcommands/maintenance/maintenance.go b/subcommands/maintenance/maintenance.go index b2d9e50a8..206800fb4 100644 --- a/subcommands/maintenance/maintenance.go +++ b/subcommands/maintenance/maintenance.go @@ -205,7 +205,7 @@ func (cmd *Maintenance) colourPass(ctx *appcontext.AppContext, cache *caching.Ma } } - fmt.Fprintf(ctx.Stdout, "maintenance: Coloured %d packfiles (%d orphaned) for deletion\n", coloredPackfiles, orphanedPackfiles) + fmt.Printf("maintenance: Coloured %d packfiles (%d orphaned) for deletion\n", coloredPackfiles, orphanedPackfiles) if coloredPackfiles > 0 { duration, err := time.ParseDuration(os.Getenv("PLAKAR_GRACEPERIOD")) @@ -225,7 +225,7 @@ func (cmd *Maintenance) colourPass(ctx *appcontext.AppContext, cache *caching.Ma } } - fmt.Fprintf(ctx.Stdout, "Coloured packfiles are scheduled to be removed in %s\n", humanDuration) + fmt.Printf("Coloured packfiles are scheduled to be removed in %s\n", humanDuration) if err := repoWriter.CommitTransaction(cmd.maintenanceID); err != nil { return err @@ -250,7 +250,7 @@ func (cmd *Maintenance) sweepPass(ctx *appcontext.AppContext, cache *caching.Mai // because we could have had a concurrent backup with the coloring // phase. if cache.HasPackfile(packfileMAC) { - fmt.Fprintf(ctx.Stderr, "maintenance: Concurrent backup used %x, uncolouring the packfile.\n", packfileMAC) + fmt.Fprintf(os.Stderr, "maintenance: Concurrent backup used %x, uncolouring the packfile.\n", packfileMAC) cmd.repository.RemoveDeletedPackfile(packfileMAC) continue } @@ -258,7 +258,7 @@ func (cmd *Maintenance) sweepPass(ctx *appcontext.AppContext, cache *caching.Mai // First thing we remove the packfile entry from our state, this means // that now effectively all of its blob are unreachable if err := cmd.repository.RemovePackfile(packfileMAC); err != nil { - fmt.Fprintf(ctx.Stderr, "maintenance: Failed to remove packfile %s from state\n", packfileMAC) + fmt.Fprintf(os.Stderr, "maintenance: Failed to remove packfile %s from state\n", packfileMAC) continue } @@ -270,18 +270,18 @@ func (cmd *Maintenance) sweepPass(ctx *appcontext.AppContext, cache *caching.Mai // just orphaned plus potential orphan blobs from aborted backups etc. for blob, err := range cmd.repository.ListOrphanBlobs() { if err != nil { - fmt.Fprintf(ctx.Stderr, "maintenance: Failed to fetch orphaned blob\n") + fmt.Fprintf(os.Stderr, "maintenance: Failed to fetch orphaned blob\n") continue } blobRemoved++ if err := cmd.repository.RemoveBlob(blob.Type, blob.Blob, blob.Location.Packfile); err != nil { // No hurt in this failing, we just have cruft left around, but they are unreachable anyway. - fmt.Fprintf(ctx.Stderr, "maintenance: garbage orphaned blobs pass failed to remove blob %x, type %s\n", blob.Blob, blob.Type) + fmt.Fprintf(os.Stderr, "maintenance: garbage orphaned blobs pass failed to remove blob %x, type %s\n", blob.Blob, blob.Type) } } - fmt.Fprintf(ctx.Stdout, "maintenance: %d blobs and %d packfiles were removed\n", blobRemoved, len(toDelete)) + fmt.Printf("maintenance: %d blobs and %d packfiles were removed\n", blobRemoved, len(toDelete)) if len(toDelete) > 0 { if err := cmd.repository.PutCurrentState(); err != nil { @@ -292,7 +292,7 @@ func (cmd *Maintenance) sweepPass(ctx *appcontext.AppContext, cache *caching.Mai if doDeletion { for packfileMAC := range toDelete { if err := cmd.repository.DeletePackfile(packfileMAC); err != nil { - fmt.Fprintf(ctx.Stderr, "maintenance: Sweep pass failed to delete packfile %x, skipping it\n", packfileMAC) + fmt.Fprintf(os.Stderr, "maintenance: Sweep pass failed to delete packfile %x, skipping it\n", packfileMAC) } } } @@ -333,22 +333,22 @@ func (cmd *Maintenance) Execute(ctx *appcontext.AppContext, repo *repository.Rep cache, err := repo.AppContext().GetCache().Maintenance(repo.Configuration().RepositoryID) if err != nil { - fmt.Fprintf(ctx.Stderr, "maintenance: Failed to open local cache %s\n", err) + fmt.Fprintf(os.Stderr, "maintenance: Failed to open local cache %s\n", err) return 1, err } if err := cmd.updateCache(ctx, cache); err != nil { - fmt.Fprintf(ctx.Stderr, "maintenance: Failed to update local cache %s\n", err) + fmt.Fprintf(os.Stderr, "maintenance: Failed to update local cache %s\n", err) return 1, err } if err := cmd.colourPass(ctx, cache); err != nil { - fmt.Fprintf(ctx.Stderr, "maintenance: Colouring pass failed %s\n", err) + fmt.Fprintf(os.Stderr, "maintenance: Colouring pass failed %s\n", err) return 1, err } if err := cmd.sweepPass(ctx, cache); err != nil { - fmt.Fprintf(ctx.Stderr, "maintenance: Sweep pass failed %s\n", err) + fmt.Fprintf(os.Stderr, "maintenance: Sweep pass failed %s\n", err) return 1, err } diff --git a/subcommands/pkg/build.go b/subcommands/pkg/build.go index e82415ee6..b6ff74363 100644 --- a/subcommands/pkg/build.go +++ b/subcommands/pkg/build.go @@ -89,7 +89,7 @@ func (cmd *PkgBuild) Execute(ctx *appcontext.AppContext, repo *repository.Reposi } make := exec.Command("make", args...) - fmt.Fprintln(ctx.Stderr, make.String()) + fmt.Fprintln(os.Stderr, make.String()) if err := make.Run(); err != nil { return 1, fmt.Errorf("make failed: %w", err) } diff --git a/subcommands/pkg/create.go b/subcommands/pkg/create.go index 825cb29bc..8eb78558b 100644 --- a/subcommands/pkg/create.go +++ b/subcommands/pkg/create.go @@ -168,6 +168,6 @@ func (cmd *PkgCreate) Execute(ctx *appcontext.AppContext, _ *repository.Reposito return 1, fmt.Errorf("failed to package all the files") } - fmt.Fprintf(ctx.Stdout, "Plugin created successfully: %s\n", cmd.Out) + fmt.Printf("Plugin created successfully: %s\n", cmd.Out) return 0, nil } diff --git a/subcommands/pkg/list.go b/subcommands/pkg/list.go index e96c30cb3..65bbe2b0d 100644 --- a/subcommands/pkg/list.go +++ b/subcommands/pkg/list.go @@ -76,9 +76,9 @@ func (cmd *PkgList) Execute(ctx *appcontext.AppContext, _ *repository.Repository for _, pkg := range packages { if cmd.LongName { - fmt.Fprintln(ctx.Stdout, pkg.PkgName()) + fmt.Println(pkg.PkgName()) } else { - fmt.Fprintln(ctx.Stdout, pkg.PkgNameAndVersion()) + fmt.Println(pkg.PkgNameAndVersion()) } } diff --git a/subcommands/prune/prune.go b/subcommands/prune/prune.go index 52fdc5b2a..8df9c37b7 100644 --- a/subcommands/prune/prune.go +++ b/subcommands/prune/prune.go @@ -185,7 +185,7 @@ func (cmd *Prune) Execute(ctx *appcontext.AppContext, repo *repository.Repositor } return ti.After(tj) }) - fmt.Fprintf(ctx.Stdout, "prune: would keep %d and delete %d snapshot(s), run with -apply to proceed\n", len(reasons)-len(toDelete), len(toDelete)) + fmt.Printf("prune: would keep %d and delete %d snapshot(s), run with -apply to proceed\n", len(reasons)-len(toDelete), len(toDelete)) l := 0 for _, e := range entries { l = max(l, len(e.prefix)) @@ -196,9 +196,9 @@ func (cmd *Prune) Execute(ctx *appcontext.AppContext, repo *repository.Repositor } r := e.reason if r.Rule == "" { - fmt.Fprintf(ctx.Stdout, "%-8s %s reason=%s\n", e.action, e.prefix, e.reason.Note) + fmt.Printf("%-8s %s reason=%s\n", e.action, e.prefix, e.reason.Note) } else { - fmt.Fprintf(ctx.Stdout, "%-8s %s match=%s:%s rank=%d cap=%d\n", + fmt.Printf("%-8s %s match=%s:%s rank=%d cap=%d\n", e.action, e.prefix, r.Rule, r.Bucket, r.Rank, r.Cap) } } diff --git a/subcommands/rm/rm.go b/subcommands/rm/rm.go index d472bf527..c50b5b428 100644 --- a/subcommands/rm/rm.go +++ b/subcommands/rm/rm.go @@ -130,13 +130,13 @@ func (cmd *Rm) Execute(ctx *appcontext.AppContext, repo *repository.Repository) } return ti.After(tj) }) - fmt.Fprintf(ctx.Stdout, "rm: would remove these %d snapshot(s), run with -apply to proceed\n", len(matches)) + fmt.Printf("rm: would remove these %d snapshot(s), run with -apply to proceed\n", len(matches)) l := 0 for _, e := range entries { l = max(l, len(e.prefix)) } for _, e := range entries { - fmt.Fprintf(ctx.Stdout, "%s\n", e.prefix) + fmt.Printf("%s\n", e.prefix) } return 0, nil } diff --git a/subcommands/service/disable.go b/subcommands/service/disable.go index 42f7d0754..cc22b3284 100644 --- a/subcommands/service/disable.go +++ b/subcommands/service/disable.go @@ -57,7 +57,7 @@ func (cmd *ServiceDisable) Execute(ctx *appcontext.AppContext, repo *repository. if err := sc.SetServiceStatus(cmd.Service, false); err != nil { return 1, err } - fmt.Fprintf(ctx.Stdout, "disabled\n") + fmt.Printf("disabled\n") return 0, nil } diff --git a/subcommands/service/enable.go b/subcommands/service/enable.go index a502841b3..1d8408a6d 100644 --- a/subcommands/service/enable.go +++ b/subcommands/service/enable.go @@ -57,7 +57,7 @@ func (cmd *ServiceEnable) Execute(ctx *appcontext.AppContext, repo *repository.R if err := sc.SetServiceStatus(cmd.Service, true); err != nil { return 1, err } - fmt.Fprintf(ctx.Stdout, "enabled\n") + fmt.Printf("enabled\n") return 0, nil } diff --git a/subcommands/service/list.go b/subcommands/service/list.go index 91ca9ef5e..4e675550c 100644 --- a/subcommands/service/list.go +++ b/subcommands/service/list.go @@ -54,7 +54,7 @@ func (cmd *ServiceList) Execute(ctx *appcontext.AppContext, repo *repository.Rep return 1, err } for _, svc := range list { - fmt.Fprintf(ctx.Stdout, "%s\n", svc.Name) + fmt.Printf("%s\n", svc.Name) } return 0, nil diff --git a/subcommands/service/show.go b/subcommands/service/show.go index a2871029e..d3d4e782d 100644 --- a/subcommands/service/show.go +++ b/subcommands/service/show.go @@ -4,6 +4,7 @@ import ( "encoding/json" "flag" "fmt" + "os" "github.com/PlakarKorp/kloset/repository" "github.com/PlakarKorp/plakar/appcontext" @@ -54,9 +55,9 @@ func (cmd *ServiceShow) Execute(ctx *appcontext.AppContext, repo *repository.Rep } if cmd.AsJson { - err = json.NewEncoder(ctx.Stdout).Encode(map[string]any{cmd.Service: config}) + err = json.NewEncoder(os.Stdout).Encode(map[string]any{cmd.Service: config}) } else { - err = yaml.NewEncoder(ctx.Stdout).Encode(map[string]any{cmd.Service: config}) + err = yaml.NewEncoder(os.Stdout).Encode(map[string]any{cmd.Service: config}) } if err != nil { return 1, fmt.Errorf("failed to encode config: %w", err) diff --git a/subcommands/service/status.go b/subcommands/service/status.go index 8634b6961..b9c3a56e4 100644 --- a/subcommands/service/status.go +++ b/subcommands/service/status.go @@ -59,9 +59,9 @@ func (cmd *ServiceStatus) Execute(ctx *appcontext.AppContext, repo *repository.R return 1, err } if status { - fmt.Fprintf(ctx.Stdout, "status: enabled\n") + fmt.Printf("status: enabled\n") } else { - fmt.Fprintf(ctx.Stdout, "status: disabled\n") + fmt.Printf("status: disabled\n") } return 0, nil } diff --git a/subcommands/ui/ui.go b/subcommands/ui/ui.go index f26de6d71..3dfd88e8d 100644 --- a/subcommands/ui/ui.go +++ b/subcommands/ui/ui.go @@ -22,6 +22,7 @@ package ui import ( "flag" "fmt" + "os" "github.com/PlakarKorp/kloset/repository" "github.com/PlakarKorp/plakar/appcontext" @@ -79,7 +80,7 @@ func (cmd *Ui) Execute(ctx *appcontext.AppContext, repo *repository.Repository) err := v2.Ui(repo, ctx, cmd.Addr, &ui_opts) if err != nil { - fmt.Fprintf(ctx.Stderr, "ui: %s\n", err) + fmt.Fprintf(os.Stderr, "ui: %s\n", err) return 1, err } return 0, err diff --git a/subcommands/version/version_test.go b/subcommands/version/version_test.go index a8285f45a..906cfffb6 100644 --- a/subcommands/version/version_test.go +++ b/subcommands/version/version_test.go @@ -8,8 +8,8 @@ import ( "strings" "testing" - "github.com/PlakarKorp/plakar/appcontext" "github.com/PlakarKorp/kloset/repository" + "github.com/PlakarKorp/plakar/appcontext" "github.com/PlakarKorp/plakar/utils" "github.com/stretchr/testify/require" ) diff --git a/ui/v2/ui.go b/ui/v2/ui.go index 1351a397c..cf8602c4b 100644 --- a/ui/v2/ui.go +++ b/ui/v2/ui.go @@ -90,7 +90,7 @@ func Ui(repo *repository.Repository, ctx *appcontext.AppContext, addr string, op repo.Logger().Printf("you can access the webUI at %s", url) } } - fmt.Fprintf(repo.AppContext().Stdout, "launching webUI at %s\n", url) + fmt.Printf("launching webUI at %s\n", url) var handler http.Handler = server if opts.Cors {