0

As answered in ddev exec: command not found (.bash_aliases) shell scripts in .ddev/commands/web are fantastic.

Is it also possible to call a command from another one? Like

#!/bin/bash

# pull prod content to local

dump_remote_database
sync_down_files
import_database

Which would (theoretically) call three separate commands defined in . ddev/commands/web

Currently I get

/mnt/ddev_config/commands/web/sync_down: line 5: dump_remote_database: command not found
/mnt/ddev_config/commands/web/sync_down: line 6: sync_down_files: command not found
/mnt/ddev_config/commands/web/sync_down: line 7: import_database: command not found
Urs
  • 4,984
  • 7
  • 54
  • 116

1 Answers1

2

On a host command you could call another ddev command, but not web or other command, because they're executing inside the container and done even know that ddev exists.

So with a host command, for example ddev relaunch in .ddev/commands/host/relaunch, you could have this, where relaunch calls ddev launch:

#!/bin/bash

## Description: Launch a browser with drupal /user
## Usage: relaunch [path]
## Example: "ddev relaunch"

ddev launch /user

With a web container command though, you're executing inside the web container (which doesn't even know that ddev exists, it's its own little world). So in that case you might have to copy/paste some feature of another web command.

Lets say you don't like the built-in drush.example enough and you want just a "drushuli" command. Whereas the drush.example uses drush directly, you can just use drush directly yourself (inside the web container) with drush uli. So I'll copy .ddev/commands/drush.example and come up with:

#!/bin/bash

## Description: Run drush uli inside the web container
## Usage: drushuli [flags] [args]
## Example: "ddev drushuli"

drush uli

It's a pretty silly example, but you get the picture. Use the tools that are available to you in the environment you're working with.

rfay
  • 9,963
  • 1
  • 47
  • 89
  • To clarify: so one web command cannot call another web command? – Urs Feb 17 '20 at 22:29
  • 1
    @Urs No, but a custom web command can DO whatever another custom web command might do... – rfay Feb 17 '20 at 22:39
  • Thanks @rfay - I think I get this. What I wanted was to modularize a web command into smaller chunks so I could call the individual „functions“ directly and avoid code repetitions. – Urs Feb 23 '20 at 08:12
  • 1
    Another option for you: The web commands are all in the container at /mnt/ddev_config/commands/web/ so you could call them directly. Or add that to the $PATH. – rfay Feb 29 '20 at 20:09