Skip to content

Commit 1bf22e2

Browse files
committed
cmd/age-keygen: print the public key to standard error
1 parent 3d73da5 commit 1bf22e2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cmd/age-keygen/keygen.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ package main
99
import (
1010
"flag"
1111
"fmt"
12-
"io"
1312
"log"
1413
"os"
1514
"time"
1615

1716
"filippo.io/age/internal/age"
17+
"golang.org/x/crypto/ssh/terminal"
1818
)
1919

2020
func main() {
@@ -46,12 +46,16 @@ func main() {
4646
generate(out)
4747
}
4848

49-
func generate(out io.Writer) {
49+
func generate(out *os.File) {
5050
k, err := age.GenerateX25519Identity()
5151
if err != nil {
5252
log.Fatalf("Internal error: %v", err)
5353
}
5454

55+
if !terminal.IsTerminal(int(out.Fd())) {
56+
fmt.Fprintf(os.Stderr, "Public key: %s\n", k.Recipient())
57+
}
58+
5559
fmt.Fprintf(out, "# created: %s\n", time.Now().Format(time.RFC3339))
5660
fmt.Fprintf(out, "# public key: %s\n", k.Recipient())
5761
fmt.Fprintf(out, "%s\n", k)

0 commit comments

Comments
 (0)