feat: add output flat to decrypt subcommand (#15)

This commit is contained in:
Dawid Wysokiński 2022-05-21 07:30:23 +02:00 committed by GitHub
parent eaebefc9c6
commit f59e1db9a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 4 deletions

24
main.go
View File

@ -66,10 +66,11 @@ func newApp() (*cli.App, error) {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "path",
Usage: "path to encrypted andotp file",
Aliases: []string{"p"},
Usage: "path to andotp backup file",
Required: false,
DefaultText: "$HOME/.otp_accounts.json.aes",
Value: path.Join(dirname, ".otp_accounts.json.aes"),
DefaultText: "$HOME/.otp_accounts.json",
Value: path.Join(dirname, ".otp_accounts.json"),
},
&cli.StringFlag{
Name: "password",
@ -108,10 +109,25 @@ func newDecryptCommand() *cli.Command {
return fmt.Errorf("something went wrong while decrypting file: %w", err)
}
fmt.Print(string(result))
output := c.String("output")
if output != "" {
if err := os.WriteFile(output, result, 0600); err != nil {
return fmt.Errorf("something went wrong while saving file: %w", err)
}
} else {
fmt.Print(string(result))
}
return nil
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "output",
Usage: "Write to file instead of stdout",
Aliases: []string{"o"},
Required: false,
},
},
}
}