Is there a way to filter out the Info from https://repo.packagist.org?

Viewed 29

Composer sometimes deliveres more or less usefull/relevant/interestig "Info from https://repo.packagist.org: ...".

Is there a way to not show this message?

Maybe a way to route it through a custom shell command and filter out certain strings?

2 Answers

Is there a way to not show this message?

The short answer is the -q, --quiet command-line option. It suppresses other output, too. Exit status is preserved.

Maybe a way to route it through a custom shell command and filter out certain strings?

You have not shared which shell, but this is certainly possible. Given on your system there is unbuffer(1) and bash(1) as /bin/bash, you could have an executable named composer within earlier in the PATH than the installed composer(1) one that filters that line out while running composer(1) unbuffer(1)ed.

As this depends on your shell configuration it is perhaps better answered with a file named install.sh that can be sourced afterwards:

# usage: . ./install.sh

utility_name=composer
utility_path_name="$(which "$utility_name")"
wrapper_path="$PWD"

if [ "$wrapper_path/$utility_name" = "$utility_path_name" ]; then
  echo "$utility_name: already installed: $utility_path_name" >&2
  return 1
fi

<< STUB tee "$utility_name"
#!/bin/bash
COMPOSER="$utility_path_name"
unbuffer "\$COMPOSER" "\$@" > >(sed -u '/^.*Info from https:\/\/repo\.packagist\.org:/d' )
STUB

chmod u+x -- "$utility_name"

PATH="$wrapper_path:$PATH"

which "$utility_name"

composer --version

To activate the wrapper, source the install.sh file:

$ . ./install.sh

You can then run every composer ... command with this noise reduction filter.

The actual wrapper is relatively thin (output yours after sourcing install.sh for comparison as paths differ):

$ cat composer
#!/bin/bash
COMPOSER="/home/user/.local/bin/composer"
unbuffer "$COMPOSER" "$@" > >(sed -u '/^.*Info from https:\/\/repo\.packagist\.org:/d' )

In principle this is independent to composer itself, just an output filter with sed(1) and wrapping a command-line utility.


Within CI you may want to do things differently, e.g. hiding all output until an error occurs. chronic(1) can do this.

Related