mirror of
https://github.com/foomo/posh-providers.git
synced 2025-10-16 12:35:41 +00:00
feat(onepassword/onepassword): add download file
This commit is contained in:
parent
c0a7b6d8d4
commit
e0327f0da1
@ -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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user