feat: export in a file
This commit is contained in:
parent
5fb2c5ee1c
commit
48a47144a1
4 changed files with 16 additions and 7 deletions
|
@ -11,6 +11,10 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
|
|||
|
||||
- Test build with travis
|
||||
|
||||
### Changed
|
||||
|
||||
- Export in a file
|
||||
|
||||
## v1.1.0 - 2019-07-23
|
||||
|
||||
### Added
|
||||
|
|
|
@ -298,5 +298,10 @@ func (c *Cli) ExportWallet() {
|
|||
c.error(fmt.Sprintf("%s", err))
|
||||
}
|
||||
|
||||
fmt.Println(data)
|
||||
err = ioutil.WriteFile(*EXPORT, data, 0600)
|
||||
if err != nil {
|
||||
c.error(fmt.Sprintf("%s", err))
|
||||
}
|
||||
|
||||
fmt.Println("the export was successful")
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ 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")
|
||||
IMPORT = flag.String("import", "", "import entries from a json file")
|
||||
EXPORT = flag.String("export", "", "json file path to export a wallet")
|
||||
IMPORT = flag.String("import", "", "json file path to import entries")
|
||||
HELP = flag.Bool("help", false, "print this help message")
|
||||
)
|
||||
|
||||
|
@ -65,7 +65,7 @@ func Run() {
|
|||
cli.deleteEntry()
|
||||
} else if *IMPORT != "" {
|
||||
cli.ImportWallet()
|
||||
} else if *EXPORT {
|
||||
} else if *EXPORT != "" {
|
||||
cli.ExportWallet()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,11 +210,11 @@ func (w *Wallet) Import(data []byte) error {
|
|||
}
|
||||
|
||||
// Export a wallet to json
|
||||
func (w *Wallet) Export() (string, error) {
|
||||
func (w *Wallet) Export() ([]byte, error) {
|
||||
data, err := json.Marshal(&w.Entries)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
return data, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue