feat: export in a file

This commit is contained in:
Adrien Waksberg 2019-07-24 18:48:47 +02:00
parent 5fb2c5ee1c
commit 48a47144a1
4 changed files with 16 additions and 7 deletions

View file

@ -11,6 +11,10 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)
- Test build with travis - Test build with travis
### Changed
- Export in a file
## v1.1.0 - 2019-07-23 ## v1.1.0 - 2019-07-23
### Added ### Added

View file

@ -298,5 +298,10 @@ func (c *Cli) ExportWallet() {
c.error(fmt.Sprintf("%s", err)) 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")
} }

View file

@ -37,8 +37,8 @@ var(
DIGIT = flag.Bool("digit", false, "use digit to generate a random password") DIGIT = flag.Bool("digit", false, "use digit to generate a random password")
LETTER = flag.Bool("letter", false, "use letter 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") SPECIAL = flag.Bool("special", false, "use special chars to generate a random password")
EXPORT = flag.Bool("export", false, "export a wallet in json format") EXPORT = flag.String("export", "", "json file path to export a wallet")
IMPORT = flag.String("import", "", "import entries from a json file") IMPORT = flag.String("import", "", "json file path to import entries")
HELP = flag.Bool("help", false, "print this help message") HELP = flag.Bool("help", false, "print this help message")
) )
@ -65,7 +65,7 @@ func Run() {
cli.deleteEntry() cli.deleteEntry()
} else if *IMPORT != "" { } else if *IMPORT != "" {
cli.ImportWallet() cli.ImportWallet()
} else if *EXPORT { } else if *EXPORT != "" {
cli.ExportWallet() cli.ExportWallet()
} }
} }

View file

@ -210,11 +210,11 @@ func (w *Wallet) Import(data []byte) error {
} }
// Export a wallet to json // Export a wallet to json
func (w *Wallet) Export() (string, error) { func (w *Wallet) Export() ([]byte, error) {
data, err := json.Marshal(&w.Entries) data, err := json.Marshal(&w.Entries)
if err != nil { if err != nil {
return "", err return []byte{}, err
} }
return string(data), nil return data, nil
} }