From 4521979dccc275532bcc053174b2a03cf0d2156b Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Thu, 16 May 2024 09:39:01 +1200 Subject: [PATCH] fix: Skip hidden directories when creating commands (#6081) --- cmd/ddev/cmd/commands.go | 4 ++++ cmd/ddev/cmd/commands_test.go | 2 ++ .../global_commands/.hiddendir/not-a-command | 7 +++++++ 3 files changed, 13 insertions(+) create mode 100644 cmd/ddev/cmd/testdata/TestCustomCommands/global_commands/.hiddendir/not-a-command diff --git a/cmd/ddev/cmd/commands.go b/cmd/ddev/cmd/commands.go index bd0032484a2..25ccc960d98 100644 --- a/cmd/ddev/cmd/commands.go +++ b/cmd/ddev/cmd/commands.go @@ -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 diff --git a/cmd/ddev/cmd/commands_test.go b/cmd/ddev/cmd/commands_test.go index c80e35b283f..8d19646f154 100644 --- a/cmd/ddev/cmd/commands_test.go +++ b/cmd/ddev/cmd/commands_test.go @@ -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) @@ -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() diff --git a/cmd/ddev/cmd/testdata/TestCustomCommands/global_commands/.hiddendir/not-a-command b/cmd/ddev/cmd/testdata/TestCustomCommands/global_commands/.hiddendir/not-a-command new file mode 100644 index 00000000000..594a0beb288 --- /dev/null +++ b/cmd/ddev/cmd/testdata/TestCustomCommands/global_commands/.hiddendir/not-a-command @@ -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"