Skip to content

Commit

Permalink
fix: Skip hidden directories when creating commands
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Apr 11, 2024
1 parent b815b8e commit 743b90b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/ddev/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func addCustomCommands(rootCmd *cobra.Command) error {
if !fileutil.IsDirectory(serviceDirOnHost) {
continue
}
// Skip hidden directories as well.
if strings.HasPrefix(filepath.Base(serviceDirOnHost), ".") {
continue
}
commandFiles, err := fileutil.ListFilesInDir(serviceDirOnHost)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cmd/ddev/cmd/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestCustomCommands(t *testing.T) {
assert.NotContains(out, "testwebglobal global (global shell web container command)")
assert.NotContains(out, "testhostcmd global")
assert.NotContains(out, "testwebcmd global")
assert.NotContains(out, "not-a-command")

out, err = exec.RunHostCommand(DdevBin, "testhostglobal-noproject", "hostarg1", "hostarg2", "--hostflag1")
assert.NoError(err)
Expand Down Expand Up @@ -140,6 +141,7 @@ func TestCustomCommands(t *testing.T) {
assert.Contains(out, "testwebglobal global (global shell web container command)")
assert.NotContains(out, "testhostcmd global") //the global testhostcmd should have been overridden by the project one
assert.NotContains(out, "testwebcmd global") //the global testwebcmd should have been overridden by the project one
assert.NotContains(out, "not-a-command")

// Have to do app.Start() because commands are copied into containers on start
err = app.Start()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

## Description: not-a-command global
## Usage: not-a-command
## Example: "ddev not-a-command"

echo "this file shouldn't display in the commands list"

0 comments on commit 743b90b

Please sign in to comment.