Open jameswilson opened 1 week ago
Seems like a reasonable feature request. I asked for this at https://github.com/drush-ops/drush/pull/2726#discussion_r113791118. I think config:status is a good place for this, or a new command as you've proposed.
FYI Drush already has --quiet and --simulate global options. Not all commands support them.
Is your feature request related to a problem? Please describe. Currently, the
drush config:import --no --diff
command outputs a configuration diff and does not execute the import, as expected when the--no
flag is used. However, the command still exits with status code1
, indicating a failure. This is problematic when the intent is to retrieve a config diff without performing an import or generating an error in scripts or logs.Many users, including myself, are frustrated by this behavior because the command, in this context, performs exactly as intended—outputting a diff and abstaining from importing—yet it results in a "failed" exit status. This complicates scripting and logging when only a diff is needed without triggering a script failure.
Current output,
Describe the solution you'd like
Introduce a dedicated command
drush config:diff
.A
config:diff
command will enable diff-only output without the failed exit code, WARNING, or error messages. This new command should allow users to view the configuration differences between the current and new config states without triggering an error status, ensuring compatibility with scripts or logging processes that expect a successful run. The command can be considered analogous togit diff
and may in fact pass through status codes from the underlying command used internally to generate the diff.The desired behavior is for the diff command to exit with code
0
when it completes successfully, even if no import takes place, reflecting the intention of the--no
or--dry-run
(see below) functionality.Support
--reverse
flag.In the case of a new command
drush config:diff
should also allow a--reverse
flag, analogous to thegit diff -R
flag to swap the two inputs; that is, show differences from staged config to the active config in the codebase (likeconfig:export --diff
) as opposed to the other way around (likeconfig:import --diff
).Support
--quiet
mode for scripting.git diff
has a--quiet
option that returns a status code of 0 or 1 as a quick way to detect if there are changes in the local working copy. Such a feature would be a useful addition for bothdrush config:diff
anddrush config:status
config:diff --quiet
(or evenconfig:status --quiet
) could be a new-and-improved alternative to the currently documented approach ofdrush config:status 2>&1 | grep "No differences"
.Describe alternatives you've considered
--dry-run
option toconfig:import
(andconfig:export
), to be used instead of the current--no
flag, which is typically more consistent with other CLI conventions where a dry-run indicates no action will occur to avoid the exit code1
. I decided against this alternative for the proposal because the reasonable expectation of a dry-run flag on a configuration import or export task would be used to determine if the import/export would work without errors. While such a behavior might be useful, it seems potentially very hard to implement and lies outside the scope of this issue.--diff-only
option toconfig:status
, so that configuration differences can be reviewed independently of the import command, similar togit diff
functionality. I decided against this alternative because it prevents future enhancements and options being added for just the diff functionality, such as the--reverse
option mentioned above. Ultimately, a dedicated command makes the most sense here.Additional context There’s a common use case where users need to see the config diff for validation or logging purposes without triggering a config import or an error. This feature would also align with common patterns in CLI tools like
diff
andgrep
, where exit code1
is informational rather than an error. The current behavior complicates script automation, as adding|| true
after the command is required to prevent script termination, which is cumbersome and unintuitive.