Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Add suffix f to formating out methods (gopasspw#1794)
Browse files Browse the repository at this point in the history
This commit renames the existing out methods that expect
a format string to include the common f suffix and introduces
new out methods without this suffix that don't accept a
format string or variadic arguments.

Fixes gopasspw#1793

RELEASE_NOTES=n/a

Signed-off-by: Dominik Schulz <[email protected]>
  • Loading branch information
dominikschulz authored Feb 15, 2021
1 parent ce8498c commit 08b7d56
Show file tree
Hide file tree
Showing 78 changed files with 372 additions and 329 deletions.
10 changes: 5 additions & 5 deletions internal/action/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

// AliasesPrint prints all cofigured aliases
func (s *Action) AliasesPrint(c *cli.Context) error {
out.Print(c.Context, "Configured aliases:")
out.Printf(c.Context, "Configured aliases:")
aliases := pwrules.AllAliases()
keys := make([]string, 0, len(aliases))
for k := range aliases {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
out.Print(c.Context, "- %s -> %s", k, strings.Join(aliases[k], ", "))
out.Printf(c.Context, "- %s -> %s", k, strings.Join(aliases[k], ", "))
}
return nil
}
Expand All @@ -39,7 +39,7 @@ func (s *Action) AliasesAdd(c *cli.Context) error {
return err
}

out.Print(ctx, "Added alias '%s' to domain '%s'", alias, domain)
out.Printf(ctx, "Added alias %q to domain %q", alias, domain)
return nil
}

Expand All @@ -57,7 +57,7 @@ func (s *Action) AliasesRemove(c *cli.Context) error {
return err
}

out.Print(ctx, "Remove alias '%s' from domain '%s'", alias, domain)
out.Printf(ctx, "Remove alias %q from domain %q", alias, domain)
return nil
}

Expand All @@ -74,6 +74,6 @@ func (s *Action) AliasesDelete(c *cli.Context) error {
return err
}

out.Print(ctx, "Remove aliases for domain '%s'", domain)
out.Printf(ctx, "Remove aliases for domain %q", domain)
return nil
}
4 changes: 2 additions & 2 deletions internal/action/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (s *Action) Audit(c *cli.Context) error {

ctx := ctxutil.WithGlobalFlags(c)

out.Print(ctx, "Auditing passwords for common flaws ...")
out.Printf(ctx, "Auditing passwords for common flaws ...")

t, err := s.Store.Tree(ctx)
if err != nil {
Expand All @@ -31,7 +31,7 @@ func (s *Action) Audit(c *cli.Context) error {
list := t.List(tree.INF)

if len(list) < 1 {
out.Print(ctx, "No secrets found")
out.Printf(ctx, "No secrets found")
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions internal/action/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (s *Action) binaryValidate(ctx context.Context, buf []byte, name string) er
fileSum := fmt.Sprintf("%x", h.Sum(nil))
h.Reset()

debug.Log("in: %s - '%s'", fileSum, string(buf))
debug.Log("in: %s - %q", fileSum, string(buf))

var err error
buf, err = s.binaryGet(ctx, name)
Expand All @@ -226,7 +226,7 @@ func (s *Action) binaryValidate(ctx context.Context, buf []byte, name string) er
_, _ = h.Write(buf)
storeSum := fmt.Sprintf("%x", h.Sum(nil))

debug.Log("store: %s - '%s'", storeSum, string(buf))
debug.Log("store: %s - %q", storeSum, string(buf))

if fileSum != storeSum {
return fmt.Errorf("hashsum mismatch (file: %s, store: %s)", fileSum, storeSum)
Expand Down Expand Up @@ -266,7 +266,7 @@ func (s *Action) Sum(c *cli.Context) error {

h := sha256.New()
_, _ = h.Write(buf)
out.Print(ctx, "%x", h.Sum(nil))
out.Printf(ctx, "%x", h.Sum(nil))

return nil
}
14 changes: 7 additions & 7 deletions internal/action/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func (s *Action) clone(ctx context.Context, repo, mount, path string) error {
}

// clone repo
debug.Log("Cloning repo '%s' to '%s'", repo, path)
debug.Log("Cloning repo %q to %q", repo, path)
if _, err := backend.Clone(ctx, storageBackendOrDefault(ctx), repo, path); err != nil {
return ExitError(ExitGit, err, "failed to clone repo '%s' to '%s': %s", repo, path, err)
return ExitError(ExitGit, err, "failed to clone repo %q to %q: %s", repo, path, err)
}

// add mount
debug.Log("Mounting cloned repo '%s' at '%s'", path, mount)
debug.Log("Mounting cloned repo %q at %q", path, mount)
if err := s.cloneAddMount(ctx, mount, path); err != nil {
return err
}
Expand All @@ -86,7 +86,7 @@ func (s *Action) clone(ctx context.Context, repo, mount, path string) error {
}

// try to init git config
out.Print(ctx, "Configuring git repository ...")
out.Printf(ctx, "Configuring git repository ...")

// ask for git config values
username, email, err := s.cloneGetGitConfig(ctx, mount)
Expand All @@ -97,13 +97,13 @@ func (s *Action) clone(ctx context.Context, repo, mount, path string) error {
// initialize git config
if err := s.Store.RCSInitConfig(ctx, mount, username, email); err != nil {
debug.Log("Stacktrace: %+v\n", err)
out.Error(ctx, "Failed to configure git: %s", err)
out.Errorf(ctx, "Failed to configure git: %s", err)
}

if mount != "" {
mount = " " + mount
}
out.Print(ctx, "Your password store is ready to use! Have a look around: `%s list%s`\n", s.Name, mount)
out.Printf(ctx, "Your password store is ready to use! Have a look around: `%s list%s`\n", s.Name, mount)

return nil
}
Expand All @@ -123,7 +123,7 @@ func (s *Action) cloneAddMount(ctx context.Context, mount, path string) error {
if err := s.Store.AddMount(ctx, mount, path); err != nil {
return ExitError(ExitMount, err, "Failed to add mount: %s", err)
}
out.Print(ctx, "Mounted password store %s at mount point `%s` ...", path, mount)
out.Printf(ctx, "Mounted password store %s at mount point `%s` ...", path, mount)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/action/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *Action) Complete(c *cli.Context) {
ctx := ctxutil.WithGlobalFlags(c)
_, err := s.Store.IsInitialized(ctx) // important to make sure the structs are not nil
if err != nil {
out.Error(ctx, "Store not initialized: %s", err)
out.Errorf(ctx, "Store not initialized: %s", err)
return
}
list, err := s.Store.List(ctx, tree.INF)
Expand Down
4 changes: 2 additions & 2 deletions internal/action/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func (s *Action) Config(c *cli.Context) error {
func (s *Action) printConfigValues(ctx context.Context, needles ...string) {
m := s.cfg.ConfigMap()
for _, k := range filterMap(m, needles) {
out.Print(ctx, "%s: %s", k, m[k])
out.Printf(ctx, "%s: %s", k, m[k])
}
for alias, path := range s.cfg.Mounts {
if len(needles) < 1 {
out.Print(ctx, "mount '%s' => '%s'", alias, path)
out.Printf(ctx, "mount %q => %q", alias, path)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/action/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *Action) copy(ctx context.Context, from, to string, force bool) error {
}

if err := s.Store.Copy(ctx, from, to); err != nil {
return ExitError(ExitIO, err, "failed to copy from '%s' to '%s'", from, to)
return ExitError(ExitIO, err, "failed to copy from %q to %q", from, to)
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions internal/action/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ func (s *creator) createWebsite(ctx context.Context, c *cli.Context) error {
err error
genPw bool
)
out.Print(ctx, "=> Creating Website login")
out.Printf(ctx, "=> Creating Website login")
urlStr, err = termio.AskForString(ctx, fmtfn(2, "1", "URL"), urlStr)
if err != nil {
return err
}
// the hostname is used as part of the name
hostname := extractHostname(urlStr)
if hostname == "" {
return action.ExitError(action.ExitUnknown, err, "Can not parse URL '%s'. Please use 'gopass edit' to manually create the secret", urlStr)
return action.ExitError(action.ExitUnknown, err, "Can not parse URL %q. Please use 'gopass edit' to manually create the secret", urlStr)
}

username, err = termio.AskForString(ctx, fmtfn(2, "2", "Login"), username)
Expand Down Expand Up @@ -154,7 +154,7 @@ func (s *creator) createWebsite(ctx context.Context, c *cli.Context) error {
sec.Set("password-change-url", u)
}
if err := s.store.Set(ctxutil.WithCommitMessage(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
return action.ExitError(action.ExitEncrypt, err, "failed to set %q: %s", name, err)
}

return s.createPrintOrCopy(ctx, c, name, password, genPw)
Expand Down Expand Up @@ -192,7 +192,7 @@ func (s *creator) createPIN(ctx context.Context, c *cli.Context) error {
err error
genPw bool
)
out.Print(ctx, "=> Creating numerical PIN ...")
out.Printf(ctx, "=> Creating numerical PIN ...")
authority, err = termio.AskForString(ctx, fmtfn(2, "1", "Authority"), authority)
if err != nil {
return err
Expand Down Expand Up @@ -245,7 +245,7 @@ func (s *creator) createPIN(ctx context.Context, c *cli.Context) error {
sec.Set("application", application)
sec.Set("comment", comment)
if err := s.store.Set(ctxutil.WithCommitMessage(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
return action.ExitError(action.ExitEncrypt, err, "failed to set %q: %s", name, err)
}

return s.createPrintOrCopy(ctx, c, name, password, genPw)
Expand All @@ -260,7 +260,7 @@ func (s *creator) createGeneric(ctx context.Context, c *cli.Context) error {
err error
genPw bool
)
out.Print(ctx, "=> Creating generic secret ...")
out.Printf(ctx, "=> Creating generic secret ...")
shortname, err = termio.AskForString(ctx, fmtfn(2, "1", "Name"), shortname)
if err != nil {
return err
Expand Down Expand Up @@ -302,7 +302,7 @@ func (s *creator) createGeneric(ctx context.Context, c *cli.Context) error {
}
sec := secrets.New()
sec.SetPassword(password)
out.Print(ctx, fmtfn(2, "3", "Enter zero or more key value pairs for this secret:"))
out.Printf(ctx, fmtfn(2, "3", "Enter zero or more key value pairs for this secret:"))
for {
key, err := termio.AskForString(ctx, fmtfn(4, "a", "Name (enter to quit)"), "")
if err != nil {
Expand All @@ -318,7 +318,7 @@ func (s *creator) createGeneric(ctx context.Context, c *cli.Context) error {
sec.Set(key, val)
}
if err := s.store.Set(ctxutil.WithCommitMessage(ctx, "Created new entry"), name, sec); err != nil {
return action.ExitError(action.ExitEncrypt, err, "failed to set '%s': %s", name, err)
return action.ExitError(action.ExitEncrypt, err, "failed to set %q: %s", name, err)
}

return s.createPrintOrCopy(ctx, c, name, password, genPw)
Expand All @@ -327,7 +327,7 @@ func (s *creator) createGeneric(ctx context.Context, c *cli.Context) error {
// createGeneratePasssword will walk through the password generation steps
func (s *creator) createGeneratePassword(ctx context.Context, hostname string) (string, error) {
if _, found := pwrules.LookupRule(hostname); found {
out.Print(ctx, "Using password rules for %s ...", hostname)
out.Printf(ctx, "Using password rules for %s ...", hostname)
length, err := termio.AskForInt(ctx, fmtfn(4, "b", "How long?"), defaultLength)
if err != nil {
return "", err
Expand Down
10 changes: 5 additions & 5 deletions internal/action/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *Action) Delete(c *cli.Context) error {
}

if !recursive && s.Store.IsDir(ctx, name) && !s.Store.Exists(ctx, name) {
return ExitError(ExitUsage, nil, "Cannot remove '%s': Is a directory. Use 'gopass rm -r %s' to delete", name, name)
return ExitError(ExitUsage, nil, "Cannot remove %q: Is a directory. Use 'gopass rm -r %s' to delete", name, name)
}

// specifying a key is optional
Expand All @@ -42,7 +42,7 @@ func (s *Action) Delete(c *cli.Context) error {
if recursive {
debug.Log("pruning %q", name)
if err := s.Store.Prune(ctx, name); err != nil {
return ExitError(ExitUnknown, err, "failed to prune '%s': %s", name, err)
return ExitError(ExitUnknown, err, "failed to prune %q: %s", name, err)
}
debug.Log("pruned %q", name)
return nil
Expand All @@ -56,7 +56,7 @@ func (s *Action) Delete(c *cli.Context) error {

debug.Log("removing entry %q", name)
if err := s.Store.Delete(ctx, name); err != nil {
return ExitError(ExitIO, err, "Can not delete '%s': %s", name, err)
return ExitError(ExitIO, err, "Can not delete %q: %s", name, err)
}
return nil
}
Expand All @@ -65,11 +65,11 @@ func (s *Action) Delete(c *cli.Context) error {
func (s *Action) deleteKeyFromYAML(ctx context.Context, name, key string) error {
sec, err := s.Store.Get(ctx, name)
if err != nil {
return ExitError(ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err)
return ExitError(ExitIO, err, "Can not delete key %q from %q: %s", key, name, err)
}
sec.Del(key)
if err := s.Store.Set(ctxutil.WithCommitMessage(ctx, "Updated Key"), name, sec); err != nil {
return ExitError(ExitIO, err, "Can not delete key '%s' from '%s': %s", key, name, err)
return ExitError(ExitIO, err, "Can not delete key %q from %q: %s", key, name, err)
}
return nil
}
4 changes: 2 additions & 2 deletions internal/action/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Action) Edit(c *cli.Context) error {
func (s *Action) edit(ctx context.Context, c *cli.Context, name string) error {
ed := editor.Path(c)
if err := editor.Check(ctx, ed); err != nil {
out.Warning(ctx, "Failed to check editor config: %s", err)
out.Warningf(ctx, "Failed to check editor config: %s", err)
}

// get existing content or generate new one from a template
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *Action) editGetContent(ctx context.Context, name string, create bool) (
}

if !create {
out.Warning(ctx, "Entry %s not found. Creating new secret ...", name)
out.Warningf(ctx, "Entry %s not found. Creating new secret ...", name)
}

// load template if it exists
Expand Down
2 changes: 1 addition & 1 deletion internal/action/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *Action) Env(c *cli.Context) error {
}
subtree, err := l.FindFolder(name)
if err != nil {
return ExitError(ExitNotFound, nil, "Entry '%s' not found", name)
return ExitError(ExitNotFound, nil, "Entry %q not found", name)
}
subtree.SetName(name)
for _, e := range subtree.List(tree.INF) {
Expand Down
6 changes: 3 additions & 3 deletions internal/action/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func (s *Action) find(ctx context.Context, c *cli.Context, needle string, cb sho
// if we have an exact match print it
if len(choices) == 1 {
if cb == nil {
out.Print(ctx, choices[0])
out.Printf(ctx, choices[0])
return nil
}
out.OK(ctx, "Found exact match in '%s'", choices[0])
out.OKf(ctx, "Found exact match in %q", choices[0])
return cb(ctx, c, choices[0], false)
}

Expand All @@ -85,7 +85,7 @@ func (s *Action) find(ctx context.Context, c *cli.Context, needle string, cb sho
// gopass find/search was invoked directly (for scripts)
if !ctxutil.IsTerminal(ctx) || (c != nil && c.Command.Name == "find") {
for _, value := range choices {
out.Print(ctx, value)
out.Printf(ctx, value)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions internal/action/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestFind(t *testing.T) {
// find fo
c = gptest.CliCtxWithFlags(ctx, t, nil, "fo")
assert.NoError(t, act.Find(c))
assert.Contains(t, strings.TrimSpace(buf.String()), "Found exact match in 'foo'\nsecret")
assert.Contains(t, strings.TrimSpace(buf.String()), "Found exact match in \"foo\"\nsecret")
buf.Reset()

// find fo (no fuzzy search)
Expand All @@ -73,14 +73,14 @@ func TestFind(t *testing.T) {
c = gptest.CliCtxWithFlags(ctx, t, map[string]string{"clip": "true"}, "fo")
assert.NoError(t, act.Find(c))
out := strings.TrimSpace(buf.String())
assert.Contains(t, out, "Found exact match in 'foo'")
assert.Contains(t, out, "Found exact match in \"foo\"")
buf.Reset()

// safecontent case with force flag set
c = gptest.CliCtxWithFlags(ctx, t, map[string]string{"unsafe": "true"}, "fo")
assert.NoError(t, act.Find(c))
out = strings.TrimSpace(buf.String())
assert.Contains(t, out, "Found exact match in 'foo'\nsecret")
assert.Contains(t, out, "Found exact match in \"foo\"\nsecret")
buf.Reset()

// stopping with the safecontent tests
Expand Down
4 changes: 2 additions & 2 deletions internal/action/fsck.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *Action) Fsck(c *cli.Context) error {
if c.IsSet("decrypt") {
ctx = leaf.WithFsckDecrypt(ctx, c.Bool("decrypt"))
}
out.Print(ctx, "Checking store integrity ...")
out.Printf(ctx, "Checking store integrity ...")
// make sure config is in the right place
// we may have loaded it from one of the fallback locations
if err := s.cfg.Save(); err != nil {
Expand All @@ -32,7 +32,7 @@ func (s *Action) Fsck(c *cli.Context) error {
oldCfg := filepath.Join(config.Homedir(), ".gopass.yml")
if fsutil.IsFile(oldCfg) {
if err := os.Remove(oldCfg); err != nil {
out.Error(ctx, "Failed to remove old gopass config %s: %s", oldCfg, err)
out.Errorf(ctx, "Failed to remove old gopass config %s: %s", oldCfg, err)
}
}

Expand Down
Loading

0 comments on commit 08b7d56

Please sign in to comment.