Skip to content

Commit 50c9db3

Browse files
committed
move cmd package
1 parent c3079b3 commit 50c9db3

File tree

6 files changed

+55
-13
lines changed

6 files changed

+55
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dep:
77
go mod verify
88

99
build: dep
10-
go build -o bin/shamir cli/main.go
10+
go build -a -ldflags="-w -s" -o ./bin/shamir ./cmd/shamir/.
1111

1212
.PHONY: build
1313

cli/main.go

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package main
22

33
import (
44
"bufio"

cli/cmd/root.go renamed to cmd/shamir/shamir.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cmd
1+
package main
22

33
import (
44
"fmt"
@@ -13,6 +13,10 @@ var RootCmd = &cobra.Command{
1313
Use: "shamir",
1414
}
1515

16+
func main() {
17+
Execute()
18+
}
19+
1620
func Execute() {
1721
if err := RootCmd.Execute(); err != nil {
1822
fmt.Println(err)

cmd/shamir/shamir_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main_test
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
main "github.com/mvrahden/go-shamir/cmd/shamir"
8+
)
9+
10+
func setStdinAndCleanup(t *testing.T) {
11+
t.Helper()
12+
newStdin, err := os.CreateTemp("", "input-1")
13+
if err != nil {
14+
t.Fatalf("failed writing to stdin: %s", err)
15+
}
16+
newStderr, err := os.CreateTemp("", "output-1")
17+
if err != nil {
18+
t.Fatalf("failed writing to stdin: %s", err)
19+
}
20+
oldStdin := os.Stdin
21+
oldStderr := os.Stderr
22+
t.Cleanup(func() {
23+
os.Stdin = oldStdin
24+
os.Stderr = oldStderr
25+
os.Remove(newStdin.Name())
26+
os.Remove(newStderr.Name())
27+
})
28+
os.Stdin = newStdin
29+
os.Stderr = newStderr
30+
}
31+
32+
func Test(t *testing.T) {
33+
os.Args = []string{"cmd", "split", "-p", "4", "-t", "2"}
34+
setStdinAndCleanup(t)
35+
36+
_, err := os.Stdin.Write([]byte(`very very secret`))
37+
if err != nil {
38+
t.Fatalf("failed writing to stdin: %s", err)
39+
}
40+
_, err = os.Stdin.Seek(0, 0)
41+
if err != nil {
42+
t.Fatalf("failed resetting pointer of stdin: %s", err)
43+
}
44+
main.Execute()
45+
}

cli/cmd/split.go renamed to cmd/shamir/split.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package cmd
1+
package main
22

33
import (
44
"fmt"
5-
"io/ioutil"
5+
"io"
66
"os"
77

88
"github.com/hashicorp/vault/shamir"
@@ -28,7 +28,7 @@ func init() {
2828
}
2929

3030
func runSplit(cmd *cobra.Command, args []string) {
31-
secretBuf, err := ioutil.ReadAll(os.Stdin)
31+
secretBuf, err := io.ReadAll(os.Stdin)
3232
if err != nil {
3333
fmt.Fprintf(os.Stderr, "Failed to read stdin: %v\n", err)
3434
os.Exit(1)

0 commit comments

Comments
 (0)