Skip to content

Commit 285d55c

Browse files
author
grd
committed
Renamed filesystem to vaults and pkg to internal
1 parent 6a19ae9 commit 285d55c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+160
-92
lines changed

Makefile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
FREEPDM=https://github.com/grd/FreePDM
2-
FREECAD_FILES=$(FREEPDM)/ConceptOfDesign/TestFiles
32
BIN_DIR=${HOME}/bin
43
CONTAINER_NAME := freepdm
54

@@ -19,14 +18,22 @@ removevault:
1918
test:
2019
go test -v ./...
2120

22-
fstest:
23-
go test -failfast pkg/filesystem/main_test.go
21+
vaultstest:
22+
go test -failfast internal/vaults/main_test.go
2423

2524
pdmserver:
26-
go build -o $(BIN_DIR)/pdmserver cmd/pdmserver/main.go
25+
go build -o $(BIN_DIR)/pdmserver ./cmd/pdmserver
26+
pdmserver
27+
28+
runserver:
29+
go run ./cmd/pdmserver
2730

2831
pdmterm:
29-
go build -o $(BIN_DIR)/pdmterm cmd/pdmterm/main.go
32+
go build -o $(BIN_DIR)/pdmterm ./cmd/pdmterm
33+
pdmterm
34+
35+
runterm:
36+
go run ./cmd/pdmterm
3037

3138
pdmclient:
3239
go build -o $(BIN_DIR)/pdmclient cmd/pdmclient/main.go

cmd/add_users/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/rivo/tview"
1111

12-
"github.com/grd/FreePDM/pkg/config"
12+
"github.com/grd/FreePDM/internal/config"
1313
)
1414

1515
// Script for user management.

cmd/createvault/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"os"
1212
"strings"
1313

14-
"github.com/grd/FreePDM/pkg/util"
14+
"github.com/grd/FreePDM/internal/util"
1515
)
1616

1717
// Script for creating a new PDM vault.

cmd/pdmserver/logging.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func createLogFile() {
5555
logFileName := path.Join(freePdmDir, fmt.Sprintf("logs/%s.log", today))
5656

5757
fmt.Printf("logFileName = %s\n", logFileName)
58+
5859
// Open or create the log file
5960
var err error
6061
logFile, err = os.OpenFile(logFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)

cmd/pdmserver/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"log"
99
"net/http"
1010

11-
"github.com/grd/FreePDM/pkg/shared"
11+
"github.com/grd/FreePDM/internal/shared"
1212
)
1313

1414
func main() {

cmd/pdmterm/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"fmt"
1111
"net/http"
1212

13-
"github.com/grd/FreePDM/pkg/shared"
13+
"github.com/grd/FreePDM/internal/shared"
1414
)
1515

1616
func sendCommand(command string, params map[string]string) (*shared.CommandResponse, error) {

cmd/pdmterm/commands.go

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ var (
4444
)
4545

4646
// handleCommand processes the input command and executes corresponding actions.
47-
func handleCommand(input string, directory *string) {
47+
func handleCommand(input string, directory string) {
4848
// Split the command and arguments
4949
parts := strings.Fields(input)
5050
if len(parts) == 0 {
51-
fmt.Println(Red + "No command entered.")
51+
fmt.Println(Red + "No command entered." + Reset)
5252
return
5353
}
5454

@@ -63,16 +63,18 @@ func handleCommand(input string, directory *string) {
6363
handleList()
6464
case "vault":
6565
handleVault(args[0])
66+
case "tree":
67+
handleTree(args[0])
6668
case "pwd":
6769
handlePwd()
6870
case "ls":
69-
handleLs(*directory)
71+
handleLs(directory)
7072
case "cd":
7173
if len(args) < 1 {
7274
fmt.Println(Cyan + "Usage: cd <directory>" + Reset)
7375
return
7476
}
75-
handleCd(args[0], directory)
77+
handleCd(args[0])
7678
case "exit", "quit":
7779
fmt.Println(Cyan + "Exiting the shell." + Reset)
7880
os.Exit(0)
@@ -115,19 +117,51 @@ func handleList() {
115117
resp, err := sendCommand("list", nil)
116118
if err != nil {
117119
fmt.Println(err)
118-
os.Exit(1)
119120
}
120-
if resp.Status == "error" {
121-
fmt.Println(Red + resp.Message + Reset)
121+
if resp.Error == "Failed to show the list of vaults" {
122+
fmt.Println(Red + resp.Error + Reset)
122123
} else {
123124
fmt.Printf(Cyan+"Data = %s\n"+Reset, resp.Data)
124125
}
125126
}
126127

127128
// handleVault changes the current vault.
128129
func handleVault(vault string) {
129-
currentVault = vault
130-
fmt.Printf(Cyan+"Switched to vault: %s\n", vault)
130+
resp, err := sendCommand("list", nil)
131+
if err != nil {
132+
fmt.Println(err)
133+
}
134+
if resp.Error == "Failed to show the list of vaults" {
135+
fmt.Println(Cyan + resp.Error + Reset)
136+
return
137+
}
138+
139+
for _, elem := range resp.Data {
140+
if vault == elem {
141+
currentVault = elem
142+
currentDir = "."
143+
break
144+
}
145+
}
146+
fmt.Printf(BrightGreen+"Switched to vault: %s\n"+Reset, vault)
147+
}
148+
149+
// handleTree changes the current vault.
150+
func handleTree(path string) {
151+
resp, err := sendCommand("tree", map[string]string{
152+
"path": path,
153+
})
154+
if err != nil {
155+
fmt.Println(err)
156+
}
157+
if resp.Error == "Failed to show the tree" {
158+
fmt.Println(Cyan + resp.Error + Reset)
159+
return
160+
}
161+
162+
for _, elem := range resp.Data {
163+
fmt.Println(elem)
164+
}
131165
}
132166

133167
// handleLs lists files and directories in the current directory.
@@ -137,45 +171,44 @@ func handleLs(directory string) {
137171
})
138172
if err != nil {
139173
fmt.Println(err)
140-
os.Exit(1)
141174
}
142-
fmt.Printf("Status = %s\n", resp.Status)
143-
fmt.Printf("Message = %s\n", resp.Message)
175+
fmt.Printf("Error = %s\n", resp.Error)
144176
fmt.Printf("Data = %s\n", resp.Data)
145177
}
146178

147179
// handleCd changes the current working directory.
148-
func handleCd(target string, directory *string) {
180+
func handleCd(target string) {
181+
fmt.Printf("dir = %s\n", target)
149182
if currentVault == "" {
150183
fmt.Println(Red + "First set the vault with the command vault" + Reset)
151184
return
152185
}
153186
resp, err := sendCommand("direxists", map[string]string{
154-
"path": *directory,
187+
"path": target,
155188
})
156189
if err != nil {
157190
fmt.Println(err)
158191
}
159-
if resp.Status != "success" {
160-
fmt.Println(Red + "directory does not exist" + Reset)
192+
if resp.Error != "" {
193+
fmt.Printf(Red+"directory %s does not exist\n"+Reset, target)
161194
return
162195
}
163196
if target == ".." { // Up one level
164-
if *directory != "/" {
165-
lastSlash := strings.LastIndex(*directory, "/")
166-
*directory = (*directory)[:lastSlash]
167-
if *directory == "" {
168-
*directory = "/"
197+
if target != "/" {
198+
lastSlash := strings.LastIndex(target, "/")
199+
target = (target)[:lastSlash]
200+
if target == "" {
201+
target = "/"
169202
}
170203
}
171204
} else { // Subdirectory
172-
if *directory == "/" {
173-
*directory += target
205+
if target == "/" {
206+
target += target
174207
} else {
175-
*directory += "/" + target
208+
target += "/" + target
176209
}
177210
}
178-
fmt.Printf(Cyan+"Changed directory to: %s\n", *directory)
211+
fmt.Printf(Cyan+"Changed directory to: %s\n", target)
179212
}
180213

181214
// handlePwd prints the current working directory.
@@ -193,12 +226,12 @@ func newPrompt() {
193226

194227
for {
195228
// Show prompt
196-
fmt.Printf("\033[96m%s:%s> \033[0m", currentVault, currentDir)
229+
fmt.Printf(BrightCyan+"%s:%s>"+Reset, currentVault, currentDir)
197230

198231
// Read input
199232
if scanner.Scan() {
200233
input := strings.TrimSpace(scanner.Text())
201-
handleCommand(input, &currentDir)
234+
handleCommand(input, currentDir)
202235
} else {
203236
break
204237
}

cmd/pdmterm/tree.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
)
8+
9+
// tree recursively prints the directory structure starting from root
10+
func tree(path string, indent string) error {
11+
entries, err := os.ReadDir(path) // ReadDir returns a slice of fs.DirEntry
12+
if err != nil {
13+
return err
14+
}
15+
16+
for i, entry := range entries {
17+
isLast := i == len(entries)-1
18+
prefix := "├── "
19+
nextIndent := indent + "│ "
20+
21+
if isLast {
22+
prefix = "└── "
23+
nextIndent = indent + " "
24+
}
25+
26+
fmt.Println(indent + prefix + entry.Name())
27+
28+
if entry.IsDir() {
29+
err := tree(filepath.Join(path, entry.Name()), nextIndent)
30+
if err != nil {
31+
return err
32+
}
33+
}
34+
}
35+
36+
return nil
37+
}

cmd/removevault/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"log"
1010
"os"
1111

12-
"github.com/grd/FreePDM/pkg/config"
13-
"github.com/grd/FreePDM/pkg/util"
12+
"github.com/grd/FreePDM/internal/config"
13+
"github.com/grd/FreePDM/internal/util"
1414
)
1515

1616
// A simple "quick and dirty" remove all files from testvault script
File renamed without changes.

0 commit comments

Comments
 (0)