1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
package cmd
import (
"bytes"
"io"
"os"
"filippo.io/age"
"github.com/urfave/cli/v2"
)
var TextConv = &cli.Command{
Name: "textconv",
Aliases: []string{"t"},
Description: "Git textconv",
Hidden: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "file",
Usage: "File being worked on",
Aliases: []string{"f"},
},
},
Action: actionTextConv,
}
func actionTextConv(ctx *cli.Context) error {
identities, err := ageIdentities()
if err != nil {
return err
}
fi, err := os.Open(ctx.Args().First())
if err != nil {
return err
}
defer fi.Close()
contents, err := io.ReadAll(fi)
if err != nil {
return err
}
r, err := age.Decrypt(bytes.NewReader(contents), identities...)
if err != nil {
// TODO debug print err
if _, cerr := io.Copy(os.Stdout, bytes.NewReader(contents)); cerr != nil {
return err
}
return nil
}
if _, err := io.Copy(os.Stdout, r); err != nil {
return err
}
return nil
}
|