Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] [CLI] load paths with trailing '/' #164

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/cli/lib/context_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"plandex/term"
"plandex/types"
"plandex/url"
"plandex/utils"
"strings"
"sync"

Expand Down Expand Up @@ -87,6 +88,7 @@ func MustLoadContext(resources []string, params *types.LoadContextParams) {
resource = resource[2:]
}

resource = utils.EnsureValidPath(resource)
inputFilePaths = append(inputFilePaths, resource)
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/cli/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ func EnsureMinDuration(start time.Time, minDuration time.Duration) {
time.Sleep(minDuration - elapsed)
}
}

func EnsureValidPath(path string) string {
// Remove trailing slash if it's not the root path
if len(path) > 1 && path[len(path)-1] == '/' {
path = path[:len(path)-1]
}

return path
}
25 changes: 25 additions & 0 deletions app/cli/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package utils

import (
"testing"
)

func TestEnsureValidPath(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"/home/user/", "/home/user"},
{"/", "/"},
}

for _, test := range tests {
t.Run("Path: "+test.input, func(t *testing.T) {
output := EnsureValidPath(test.input)
// t.Logf(output)
if output != test.expected {
t.Errorf("EnsureValidPath(%q) = %q; want %q", test.input, output, test.expected)
}
})
}
}