feat(onepassword/onepassword): add download file

This commit is contained in:
Kevin Franklin Kim 2024-07-12 16:19:21 +02:00
parent c0a7b6d8d4
commit e0327f0da1
No known key found for this signature in database

View File

@ -2,6 +2,8 @@ package onepassword
import (
"context"
"os"
"path"
"github.com/foomo/posh/pkg/command/tree"
"github.com/foomo/posh/pkg/log"
@ -69,6 +71,21 @@ func NewCommand(l log.Logger, op *OnePassword, opts ...CommandOption) (*Command,
},
Execute: inst.get,
},
{
Name: "download",
Description: "Download a document",
Args: tree.Args{
{
Name: "id",
Description: "Item name or uuid",
},
{
Name: "output",
Description: "Save the document to the file path instead of stdout",
},
},
Execute: inst.download,
},
{
Name: "register",
Description: "Register an account",
@ -124,6 +141,20 @@ func (c *Command) get(ctx context.Context, r *readline.Readline) error {
Run()
}
func (c *Command) download(ctx context.Context, r *readline.Readline) error {
if err := os.MkdirAll(path.Dir(r.Args().At(2)), 0700); err != nil {
return err
}
return shell.New(ctx, c.l,
"op",
"--account", c.op.cfg.Account,
"document", "get", r.Args().At(1),
"--out-file", r.Args().At(2),
).
Args(r.AdditionalArgs()...).
Run()
}
func (c *Command) register(ctx context.Context, r *readline.Readline) error {
return shell.New(ctx, c.l,
"op", "account", "add",