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
|
package main
import (
"fmt"
"github.com/spf13/cobra"
"gitlab.com/whiteboardguy/eno/internal/crud"
)
var cobraCmd = &cobra.Command{
Use: "eno",
Short: "file encryption tool",
}
var encryptCmd = &cobra.Command{
Use: "encrypt <file>",
Short: "encrypt a file",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
output, _ := cmd.Flags().GetString("output")
if output == "" {
return fmt.Errorf("output file required (-o)")
}
crud.RawEncryptFile(args[0], output)
return nil
},
}
var decryptCmd = &cobra.Command{
Use: "decrypt <file>",
Short: "decrypt a file",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
output, _ := cmd.Flags().GetString("output")
if output == "" {
return fmt.Errorf("output file required (-o)")
}
crud.RawDecryptFile(args[0], output)
return nil
},
}
func init() {
encryptCmd.Flags().StringP("output", "o", "", "output file (required)")
encryptCmd.MarkFlagRequired("output")
decryptCmd.Flags().StringP("output", "o", "", "output file (required)")
decryptCmd.MarkFlagRequired("output")
cobraCmd.AddCommand(encryptCmd, decryptCmd)
}
|