Skip to content

Commit

Permalink
feat(cli): draw/undraw selection (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeremWD authored Nov 16, 2023
1 parent 002190e commit 7dbdd76
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
43 changes: 21 additions & 22 deletions CLI/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,16 +704,9 @@ func (n *updateObjNode) execute() (interface{}, error) {
}
values = append(values, val)
}
var paths []string
if path == "_" {
paths = cmd.State.ClipBoard
} else if strings.Contains(path, "*") {
_, paths, err = cmd.GetObjectsWildcard(path)
if err != nil {
return nil, err
}
} else {
paths = []string{path}
paths, err := c.UnfoldPath(path)
if err != nil {
return nil, err
}
for _, path := range paths {
var err error
Expand Down Expand Up @@ -788,21 +781,17 @@ func (n *drawNode) execute() (interface{}, error) {
if err != nil {
return nil, err
}
if strings.Contains(path, "*") {
_, subpaths, err := cmd.GetObjectsWildcard(path)
paths, err := c.UnfoldPath(path)
if err != nil {
return nil, err
}
for _, subpath := range paths {
err = cmd.Draw(subpath, n.depth, n.force)
if err != nil {
return nil, err
}
for _, subpath := range subpaths {
err = cmd.Draw(subpath, n.depth, n.force)
if err != nil {
return nil, err
}
}
return nil, nil
} else {
return nil, cmd.Draw(path, n.depth, n.force)
}
return nil, nil
}

type undrawNode struct {
Expand All @@ -817,7 +806,17 @@ func (n *undrawNode) execute() (interface{}, error) {
if err != nil {
return nil, err
}
return nil, cmd.Undraw(path)
paths, err := c.UnfoldPath(path)
if err != nil {
return nil, err
}
for _, subpath := range paths {
err = cmd.Undraw(subpath)
if err != nil {
return nil, err
}
}
return nil, nil
}

type lsogNode struct{}
Expand Down
11 changes: 11 additions & 0 deletions CLI/controllers/commandController.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ func PWD() string {
return State.CurrPath
}

func UnfoldPath(path string) ([]string, error) {
if strings.Contains(path, "*") {
_, subpaths, err := GetObjectsWildcard(path)
return subpaths, err
}
if path == "_" {
return State.ClipBoard, nil
}
return []string{path}, nil
}

func PostObj(ent int, entity string, data map[string]any) error {
resp, err := RequestAPI("POST", "/api/"+entity+"s", data, http.StatusCreated)
if err != nil {
Expand Down

0 comments on commit 7dbdd76

Please sign in to comment.