Compare commits
2 commits
b64507ff31
...
b87fbd4991
Author | SHA1 | Date | |
---|---|---|---|
|
b87fbd4991 | ||
|
098b809310 |
3 changed files with 79 additions and 5 deletions
2
go.mod
2
go.mod
|
@ -2,6 +2,6 @@ module g.arns.lt/zordsdavini/zordfsdb-client
|
||||||
|
|
||||||
go 1.23.0
|
go 1.23.0
|
||||||
|
|
||||||
require g.arns.lt/zordsdavini/zordfsdb v1.0.1
|
require g.arns.lt/zordsdavini/zordfsdb v1.0.2
|
||||||
|
|
||||||
require g.arns.lt/zordsdavini/abcex v1.0.1 // indirect
|
require g.arns.lt/zordsdavini/abcex v1.0.1 // indirect
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,7 +1,7 @@
|
||||||
g.arns.lt/zordsdavini/abcex v1.0.1 h1:ZN/xSDQb8CiR9+jXHYp+tUtGILMeRu9PvvqhypZDkyI=
|
g.arns.lt/zordsdavini/abcex v1.0.1 h1:ZN/xSDQb8CiR9+jXHYp+tUtGILMeRu9PvvqhypZDkyI=
|
||||||
g.arns.lt/zordsdavini/abcex v1.0.1/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8=
|
g.arns.lt/zordsdavini/abcex v1.0.1/go.mod h1:YRcJgts3XZwI+LEkngpfUab3DkUAW387Irpr43hIym8=
|
||||||
g.arns.lt/zordsdavini/zordfsdb v1.0.1 h1:XM/5qR2PsGBFUwT9GrCbiPEUySoZHKP6yeRcRDCO3no=
|
g.arns.lt/zordsdavini/zordfsdb v1.0.2 h1:J2rTJa5rbG2RiSv3uQ6G8Y8LdUiZ/rPMlsdo6ilwXv8=
|
||||||
g.arns.lt/zordsdavini/zordfsdb v1.0.1/go.mod h1:gq30YNjz3yIMdI4cA5e5mK90V4Yns5NAsbwi6s8Bf3Q=
|
g.arns.lt/zordsdavini/zordfsdb v1.0.2/go.mod h1:gq30YNjz3yIMdI4cA5e5mK90V4Yns5NAsbwi6s8Bf3Q=
|
||||||
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
|
github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU=
|
||||||
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
|
github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w=
|
||||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||||
|
|
78
main.go
78
main.go
|
@ -44,7 +44,6 @@ func main() {
|
||||||
text, _ := reader.ReadString('\n')
|
text, _ := reader.ReadString('\n')
|
||||||
// convert CRLF to LF
|
// convert CRLF to LF
|
||||||
text = strings.Replace(text, "\n", "", -1)
|
text = strings.Replace(text, "\n", "", -1)
|
||||||
fmt.Println(text)
|
|
||||||
|
|
||||||
if strings.Compare("QUIT", strings.ToUpper(text)) == 0 || strings.Compare("\\Q", strings.ToUpper(text)) == 0 {
|
if strings.Compare("QUIT", strings.ToUpper(text)) == 0 || strings.Compare("\\Q", strings.ToUpper(text)) == 0 {
|
||||||
fmt.Println("\nBye o/")
|
fmt.Println("\nBye o/")
|
||||||
|
@ -64,6 +63,8 @@ DEL [path] - remove property/object/list (no confirmation)
|
||||||
SAVE [path] [value] - set value to property
|
SAVE [path] [value] - set value to property
|
||||||
CREATE [path] - create list/object in path (parent path should exist)
|
CREATE [path] - create list/object in path (parent path should exist)
|
||||||
ADD [path] - add abcex indexed object to list. Will return index
|
ADD [path] - add abcex indexed object to list. Will return index
|
||||||
|
INFO [path] - get all info about property/object/list
|
||||||
|
TREE [path] - draw db part in path with values
|
||||||
HELP - will print this help
|
HELP - will print this help
|
||||||
QUIT - exit the shell
|
QUIT - exit the shell
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ Last used path can be accessed by _
|
||||||
Last returned index (after ADD command) can be accessed by $
|
Last returned index (after ADD command) can be accessed by $
|
||||||
|
|
||||||
Short commands can be as:
|
Short commands can be as:
|
||||||
KEYS(\K), GET(\G), INC(\I), DEC(\D), NOW(\N), DEL(\R), SAVE(\S), CREATE(\C), ADD(\A), HELP(\H), QUIT(\Q)
|
KEYS(\K), GET(\G), INC(\I), DEC(\D), NOW(\N), DEL(\R), SAVE(\S), CREATE(\C), ADD(\A), INFO(\?), TREE(\T), HELP(\H), QUIT(\Q)
|
||||||
`)
|
`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -99,6 +100,61 @@ func ExecuteCommand(db zordfsdb.DB, commands string) error {
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
break
|
break
|
||||||
|
|
||||||
|
case "INFO":
|
||||||
|
case "\\?":
|
||||||
|
if len(parts) == 1 || len(parts[1]) == 0 {
|
||||||
|
return fmt.Errorf("err format: INFO [path]\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
node, ok := db.GetNode(parts[1])
|
||||||
|
if !ok {
|
||||||
|
fmt.Println("No path found.")
|
||||||
|
fmt.Println("")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("{%s} INFO\n-----------------\n", parts[1])
|
||||||
|
ntype := "property"
|
||||||
|
if node.List {
|
||||||
|
ntype = "list"
|
||||||
|
} else if node.Object {
|
||||||
|
ntype = "object"
|
||||||
|
}
|
||||||
|
fmt.Println("type:", ntype)
|
||||||
|
if ntype == "property" {
|
||||||
|
fmt.Println("value:", node.Value)
|
||||||
|
} else {
|
||||||
|
fmt.Println("keys:", db.Keys(parts[1]))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("")
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case "TREE":
|
||||||
|
case "\\T":
|
||||||
|
if len(parts) == 1 || len(parts[1]) == 0 || parts[1] == "." {
|
||||||
|
fmt.Printf("TREE\n-----------------\n\\\n")
|
||||||
|
printNodeTree(&db, 1)
|
||||||
|
fmt.Println("")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
node, ok := db.GetNode(parts[1])
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("err format: TREE [path]\n")
|
||||||
|
} else {
|
||||||
|
fmt.Printf("{%s} TREE\n-----------------\n", parts[1])
|
||||||
|
if !node.List && !node.Object {
|
||||||
|
fmt.Printf("%s: %s\n\n", node.Key, node.Value)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(node.Key)
|
||||||
|
printNodeTree(&node, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("")
|
||||||
|
break
|
||||||
|
|
||||||
case "GET":
|
case "GET":
|
||||||
case "\\G":
|
case "\\G":
|
||||||
if len(parts) == 1 || len(parts[1]) == 0 {
|
if len(parts) == 1 || len(parts[1]) == 0 {
|
||||||
|
@ -239,3 +295,21 @@ func ExecuteCommand(db zordfsdb.DB, commands string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printNodeTree(node zordfsdb.GetNodes, i int) {
|
||||||
|
for key, child := range node.GetNodes() {
|
||||||
|
j := i - 1
|
||||||
|
for j > 0 {
|
||||||
|
fmt.Printf("│ ")
|
||||||
|
j--
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("├── %s", key)
|
||||||
|
if !child.List && !child.Object {
|
||||||
|
fmt.Printf(": %s\n", child.Value)
|
||||||
|
} else {
|
||||||
|
fmt.Println("")
|
||||||
|
printNodeTree(&child, i+1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue