add output to stdout

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

32
main.go
View File

@ -50,17 +50,21 @@ func main() {
if !tools.CheckExists(flags.SrcFile, false) { if !tools.CheckExists(flags.SrcFile, false) {
log.Fatal("SrcFile not exists") log.Fatal("SrcFile not exists")
} }
dir := path.Dir(flags.DstFile) if flags.DstFile != "-" {
if !tools.CheckExists(dir, true) { dir := path.Dir(flags.DstFile)
log.Fatal("DstFile parent directory not exists") if !tools.CheckExists(dir, true) {
} log.Fatal("DstFile parent directory not exists")
if !flags.Override && tools.CheckExists(flags.DstFile, false) { }
log.Fatal("DstFile has Exists if override add flag -y ") if !flags.Override && tools.CheckExists(flags.DstFile, false) {
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
handleError(err) if flags.DstFile != "-" {
dstIO, err = os.Create(flags.DstFile)
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
handleError(err) if flags.DstFile != "-" {
dstIO, err = os.Create(flags.DstFile)
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)