How to align all recursive files when printing only files with an error?

I want to align all files in the current (recursive) directory when printing only files with an error and assign variable 1, which will be used after renaming is completed.

#!/bin/bash

lint_failed=0
find . -path ./vendor -prune -o -name '*.php' | parallel -j 4 sh -c 'php -l {} || echo -e "[FAIL] {}" && lint_failed=1';

if [ "$lint_failed" -eq "1" ]; then
    exit 1
fi

An example :

[FAIL] ./ app / Model / Example.php

No errors were found in the above code, but if I run php -l ./app/Model/Example.php, an error is returned.

+4
source share
2 answers

The team parallelalready does what you want: it goes out of 0 if all jobs complete 0, and it goes out of non-zero if any one job goes out of non-zero. paralleloutput parameters are configurable, see section for details EXIT STATUS man parallel.

script || echo , , - ( bash 4.4.7 ubuntu):

#!/bin/bash

php_lint_file()
{
    local php_file="$1"
    php -l "$php_file" &> /dev/null
    if [ "$?" -ne 0 ]
    then
        echo -e "[FAIL] $php_file"
        return 1
    fi
}

export -f php_lint_file

find . -path ./vendor -prune -o -name '*.php' | parallel -j 4 php_lint_file {}

if [ "$?" -ne 0 ]
then
    exit 1
fi
+3

PHP Parallel Lint tool, PHP , .

:

./bin/parallel-lint --exclude app --exclude vendor .

Ant build.xml:

<condition property="parallel-lint" value="${basedir}/bin/parallel-lint.bat" else="${basedir}/bin/parallel-lint">
    <os family="windows"/>
</condition>

<target name="parallel-lint" description="Run PHP parallel lint">
    <exec executable="${parallel-lint}" failonerror="true">
        <arg line="--exclude" />
        <arg path="${basedir}/app/" />
        <arg line="--exclude" />
        <arg path="${basedir}/vendor/" />
        <arg path="${basedir}" />
    </exec>
</target>
0

Source: https://habr.com/ru/post/1691706/


All Articles