Skip to content

Commit

Permalink
Add lastpass command as a wrapper for lpass
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Nov 30, 2018
1 parent a2e6e88 commit 377999a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type Config struct {
DryRun bool
Verbose bool
SourceVCSCommand string
LastPass LastPassCommandConfig
Data map[string]interface{}
funcs template.FuncMap
add addCommandConfig
keyring keyringCommandConfig
lastpass lastpassCommandConfig
}

func (c *Config) addFunc(key string, value interface{}) {
Expand Down
22 changes: 18 additions & 4 deletions cmd/lastpass.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@ import (
"fmt"
"os/exec"
"strings"

"github.com/spf13/cobra"
vfs "github.com/twpayne/go-vfs"
)

type lastpassCommandConfig struct {
lpass string
var lastpassCommand = &cobra.Command{
Use: "lastpass",
Short: "Execute the LastPass CLI",
RunE: makeRunE(config.runLastPassCommand),
}

type LastPassCommandConfig struct {
Lpass string
}

func init() {
config.lastpass.lpass = "lpass"
rootCommand.AddCommand(lastpassCommand)
config.LastPass.Lpass = "lpass"
config.addFunc("lastpass", config.lastpassFunc)
}

func (c *Config) runLastPassCommand(fs vfs.FS, cmd *cobra.Command, args []string) error {
return c.exec(append([]string{c.LastPass.Lpass}, args...))
}

func (c *Config) lastpassFunc(id string) interface{} {
// FIXME is there a better way to return errors from template funcs?
name := c.lastpass.lpass
name := c.LastPass.Lpass
args := []string{"show", "-j", id}
if c.Verbose {
fmt.Printf("%s %s\n", name, strings.Join(args, " "))
Expand Down

0 comments on commit 377999a

Please sign in to comment.