add output to stdout

This commit is contained in:
Jay 2018-03-13 16:38:52 +08:00
parent 648a3259c2
commit 8a9be9c126

16
main.go
View File

@ -50,6 +50,7 @@ func main() {
if !tools.CheckExists(flags.SrcFile, false) { if !tools.CheckExists(flags.SrcFile, false) {
log.Fatal("SrcFile not exists") log.Fatal("SrcFile not exists")
} }
if flags.DstFile != "-" {
dir := path.Dir(flags.DstFile) dir := path.Dir(flags.DstFile)
if !tools.CheckExists(dir, true) { if !tools.CheckExists(dir, true) {
log.Fatal("DstFile parent directory not exists") log.Fatal("DstFile parent directory not exists")
@ -57,10 +58,13 @@ func main() {
if !flags.Override && tools.CheckExists(flags.DstFile, false) { if !flags.Override && tools.CheckExists(flags.DstFile, false) {
log.Fatal("DstFile has Exists if override add flag -y ") log.Fatal("DstFile has Exists if override add flag -y ")
} }
flags.DstFile = tools.ParsePath(flags.DstFile)
}
flags.KeyFile = tools.ParsePath(flags.KeyFile) flags.KeyFile = tools.ParsePath(flags.KeyFile)
flags.SrcFile = tools.ParsePath(flags.SrcFile) flags.SrcFile = tools.ParsePath(flags.SrcFile)
flags.DstFile = tools.ParsePath(flags.DstFile)
// fmt.Println(flags.ToMap())
if flags.Encrypt { if flags.Encrypt {
// encrypt() // encrypt()
@ -70,8 +74,11 @@ func main() {
srcIO, err := os.Open(flags.SrcFile) srcIO, err := os.Open(flags.SrcFile)
handleError(err) handleError(err)
dstIO, err := os.Create(flags.DstFile) dstIO := os.Stdout
if flags.DstFile != "-" {
dstIO, err = os.Create(flags.DstFile)
handleError(err) handleError(err)
}
err = pgpcrypt.Encrypt2(keyIO, srcIO, dstIO) err = pgpcrypt.Encrypt2(keyIO, srcIO, dstIO)
@ -86,8 +93,11 @@ func main() {
srcIO, err := os.Open(flags.SrcFile) srcIO, err := os.Open(flags.SrcFile)
handleError(err) handleError(err)
dstIO, err := os.Create(flags.DstFile) dstIO := os.Stdout
if flags.DstFile != "-" {
dstIO, err = os.Create(flags.DstFile)
handleError(err) handleError(err)
}
err = pgpcrypt.Decrypt2(keyIO, srcIO, dstIO, flags.Password) err = pgpcrypt.Decrypt2(keyIO, srcIO, dstIO, flags.Password)
// err := pgpcrypt.Decrypt(flags.KeyFile, flags.SrcFile, flags.DstFile, flags.Password) // err := pgpcrypt.Decrypt(flags.KeyFile, flags.SrcFile, flags.DstFile, flags.Password)