Files
Dominik Schulz f2cac9f3b3 Refactor action.ExitError into its own package (#2114)
RELEASE_NOTES=n/a

Fixes #2107

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
2022-01-16 14:34:12 +01:00

35 lines
859 B
Go

package action
import (
"io/ioutil"
"github.com/gopasspw/gopass/internal/action/exit"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/internal/tpl"
"github.com/gopasspw/gopass/pkg/ctxutil"
"github.com/urfave/cli/v2"
)
// Process is a command to process a template and replace secrets contained in it.
func (s *Action) Process(c *cli.Context) error {
ctx := ctxutil.WithGlobalFlags(c)
file := c.Args().First()
if file == "" {
return exit.Error(exit.Usage, nil, "Usage: %s process <FILE>", s.Name)
}
buf, err := ioutil.ReadFile(file)
if err != nil {
return exit.Error(exit.IO, err, "Failed to read file: %s", file)
}
obuf, err := tpl.Execute(ctx, string(buf), file, nil, s.Store)
if err != nil {
return exit.Error(exit.IO, err, "Failed to process file: %s", file)
}
out.Print(ctx, string(obuf))
return nil
}