File tree 2 files changed +46
-0
lines changed
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1
1
vendor
2
2
.DS_Store
3
3
.idea
4
+ .vscode
Original file line number Diff line number Diff line change
1
+ package cmd
2
+
3
+ import (
4
+ "os"
5
+
6
+ "github.com/pinpt/go-common/v10/auth"
7
+ "github.com/spf13/cobra"
8
+ )
9
+
10
+ var decryptStringCmd = & cobra.Command {
11
+ Use : "decrypt <string> <password>" ,
12
+ Short : "decrypt a string" ,
13
+ Args : cobra .ExactArgs (2 ),
14
+ Run : func (cmd * cobra.Command , args []string ) {
15
+ slug := args [0 ]
16
+ password := args [1 ]
17
+ result , err := auth .DecryptString (slug , password )
18
+ if err != nil {
19
+ os .Stderr .WriteString (err .Error ())
20
+ os .Exit (1 )
21
+ }
22
+ os .Stdout .WriteString (result )
23
+ },
24
+ }
25
+
26
+ var encryptStringCmd = & cobra.Command {
27
+ Use : "encrypt <string> <password>" ,
28
+ Short : "encrypt a string" ,
29
+ Args : cobra .ExactArgs (2 ),
30
+ Run : func (cmd * cobra.Command , args []string ) {
31
+ slug := args [0 ]
32
+ password := args [1 ]
33
+ result , err := auth .EncryptString (slug , password )
34
+ if err != nil {
35
+ os .Stderr .WriteString (err .Error ())
36
+ os .Exit (1 )
37
+ }
38
+ os .Stdout .WriteString (result )
39
+ },
40
+ }
41
+
42
+ func init () {
43
+ rootCmd .AddCommand (decryptStringCmd )
44
+ rootCmd .AddCommand (encryptStringCmd )
45
+ }
You can’t perform that action at this time.
0 commit comments