feat: export a wallet in json

This commit is contained in:
Adrien Waksberg 2019-07-22 19:27:59 +02:00
parent 09445236a4
commit c35b543004
4 changed files with 25 additions and 0 deletions

View file

@ -12,6 +12,7 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
- Use go module to get this software
- Generate random password
- Print the expiration time of TOTP code
- Export a wallet in json
## Changed

View file

@ -254,3 +254,14 @@ func (c *Cli) copyEntry() {
}
}
}
func (c *Cli) ExportWallet() {
c.loadWallet()
data, err := c.Wallet.Export()
if err != nil {
c.error(fmt.Sprintf("%s", err))
}
fmt.Println(data)
}

View file

@ -37,6 +37,7 @@ var(
DIGIT = flag.Bool("digit", false, "use digit to generate a random password")
LETTER = flag.Bool("letter", false, "use letter to generate a random password")
SPECIAL = flag.Bool("special", false, "use special chars to generate a random password")
EXPORT = flag.Bool("export", false, "export a wallet in json format")
HELP = flag.Bool("help", false, "print this help message")
)
@ -61,5 +62,7 @@ func Run() {
cli.updateEntry()
} else if *DELETE {
cli.deleteEntry()
} else if *EXPORT {
cli.ExportWallet()
}
}

View file

@ -189,3 +189,13 @@ func (w *Wallet) UpdateEntry(entry Entry) error {
return fmt.Errorf("unknown error during the update")
}
// Export a wallet to json
func (w *Wallet) Export() (string, error) {
data, err := json.Marshal(&w.Entries)
if err != nil {
return "", err
}
return string(data), nil
}