Skip to content

Commit 8632ea4

Browse files
move some sypher methods to internal
1 parent dc9288f commit 8632ea4

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

Diff for: internal/commander/commander.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package commander
22

33
import (
44
"fmt"
5-
"github.com/sertangulveren/sypher"
5+
"github.com/sertangulveren/sypher/internal/procs"
66
"github.com/sertangulveren/sypher/internal/shared"
77
"github.com/sertangulveren/sypher/internal/utils"
88
"io/ioutil"
@@ -24,7 +24,7 @@ func Generate() {
2424

2525
// create credential for each pieces
2626
for _, item := range pieces {
27-
s := sypher.Sypher{
27+
s := procs.Sypher{
2828
Name: item,
2929
Key: utils.GenerateKey(),
3030
}
@@ -34,15 +34,15 @@ func Generate() {
3434
}
3535
s.Write([]byte(shared.DefaultContent))
3636
s.WriteKey()
37-
sypher.WriteEmbedPort()
37+
procs.WriteEmbedPort()
3838
fmt.Println("Created: ", s.Name)
3939
}
4040
fmt.Println(shared.Done)
4141
}
4242

4343
// Print credential as plain
4444
func Print() {
45-
s := sypher.Sypher{}
45+
s := procs.Sypher{}
4646
if len(shared.CmdArgs()) > 0 {
4747
s.Name = shared.CmdArgs()[0]
4848
}
@@ -57,7 +57,7 @@ func Print() {
5757

5858
// Edit credential in editor
5959
func Edit() {
60-
s := sypher.Sypher{}
60+
s := procs.Sypher{}
6161
if len(shared.CmdArgs()) > 0 {
6262
s.Name = shared.CmdArgs()[0]
6363
}
@@ -80,7 +80,7 @@ func Edit() {
8080
editorApp, err := exec.LookPath(shared.GetEditor())
8181
utils.PanicWithError(err)
8282

83-
// Generate commander to open tempfile in editor
83+
// Generate commander to open temp file in editor
8484
cmd := exec.Command(editorApp, tempFile.Name())
8585
cmd.Stdin = os.Stdin
8686
cmd.Stdout = os.Stdout

Diff for: sypher.go renamed to internal/procs/sypher.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package sypher
1+
package procs
22

33
import (
44
"bytes"
5+
"embed"
56
"github.com/sertangulveren/sypher/internal/shared"
67
"github.com/sertangulveren/sypher/internal/utils"
78
"os"
@@ -15,7 +16,9 @@ type Sypher struct {
1516
Ready bool
1617
}
1718

18-
func newSypher() *Sypher {
19+
var FS *embed.FS
20+
21+
func NewSypher() *Sypher {
1922
return &Sypher{Name: shared.DefaultName}
2023
}
2124

@@ -52,7 +55,7 @@ func (s *Sypher) readEncryptedContent() []byte {
5255
return encData
5356
}
5457

55-
encData, err = fs.ReadFile(s.fsPath())
58+
encData, err = FS.ReadFile(s.fsPath())
5659
if err == nil {
5760
// fmt.Println("sypher loaded the content from embedded file")
5861
return encData

Diff for: internal/shared/vars.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Decrypted content will be printed as below:
7676

7777
const GitIgnoreTemplate = "sypher/*.key\n"
7878

79-
const EmbedPortContent = `// File generated by sypher. DO NOT EDIT.
79+
const EmbedPortContent = `// Code generated by sypher. DO NOT EDIT.
8080
package sypher
8181
8282
import (

Diff for: tool.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package sypher
33
import (
44
"embed"
55
"errors"
6+
"github.com/sertangulveren/sypher/internal/procs"
67
"github.com/sertangulveren/sypher/internal/utils"
78
)
89

9-
var Cred *Sypher
10+
var Cred *procs.Sypher
1011

1112
var fs *embed.FS
1213

@@ -22,10 +23,10 @@ func RegisterFS(projectFs *embed.FS) {
2223
// Load to make ready to use sypher
2324
func Load(config ...Config) {
2425
if len(config) == 0 {
25-
Cred = newSypher()
26+
Cred = procs.NewSypher()
2627
} else {
2728
cfg := config[0]
28-
Cred = &Sypher{
29+
Cred = &procs.Sypher{
2930
Name: cfg.Name,
3031
Key: cfg.Key,
3132
}

0 commit comments

Comments
 (0)