mirror of https://git.jolheiser.com/git-age
57 lines
960 B
Go
57 lines
960 B
Go
|
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
|
||
|
}
|