Skip to content

Commit

Permalink
[MegaLinter] Apply linters fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
renovate[bot] authored and megalinter-bot committed Oct 12, 2024
1 parent f417c8d commit 36f75b2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 80 deletions.
1 change: 1 addition & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Available commands can be listed with the help command by posting the following
/help
```
Which returns:
>
> Command | Description
> --- | ---
> /build | Updates the Dockerfile, documentation, and other files from the yml descriptors
Expand Down
159 changes: 79 additions & 80 deletions sh/megalinter_exec
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,28 @@
#Email Author : inbar@ox.security
###############################################################################################

usage()
{
echo -e ""
echo -e "execute megalinter"
echo -e ""
echo -e "Usage"
echo -e "\tmegalinter_exec [options] --input <INPUT> --output <OUTPUT> [--capture-std <LOG>]"
echo -e ""
echo -e "Arguments"
echo -e "\t-h|-?|--help show usage (this message)"
echo -e "\t--input <INPUT> specify the directory to scan"
echo -e "\t--output <OUTPUT> specify the path for the report file to be created at"
echo -e "\t--capture-std <LOG> specify a path to write all captured STDOUT and STDERR to"
echo -e ""
echo -e "Options"
echo -e "\t-v|--verbose verbose output (useful for debugging)"
echo -e ""
echo -e "Examples"
echo -e "\t1. scan megalinter repo"
echo -e "\t\tmegalinter_exec --input /megalinter --output /tmp/output.sarif"
echo -e "\t2. scan megalinter repo with capture std"
echo -e "\t\tmegalinter_exec --input /megalinter --output /tmp/output.sarif --capture-std /tmp/out.log"
echo -e ""
usage() {
echo -e ""
echo -e "execute megalinter"
echo -e ""
echo -e "Usage"
echo -e "\tmegalinter_exec [options] --input <INPUT> --output <OUTPUT> [--capture-std <LOG>]"
echo -e ""
echo -e "Arguments"
echo -e "\t-h|-?|--help show usage (this message)"
echo -e "\t--input <INPUT> specify the directory to scan"
echo -e "\t--output <OUTPUT> specify the path for the report file to be created at"
echo -e "\t--capture-std <LOG> specify a path to write all captured STDOUT and STDERR to"
echo -e ""
echo -e "Options"
echo -e "\t-v|--verbose verbose output (useful for debugging)"
echo -e ""
echo -e "Examples"
echo -e "\t1. scan megalinter repo"
echo -e "\t\tmegalinter_exec --input /megalinter --output /tmp/output.sarif"
echo -e "\t2. scan megalinter repo with capture std"
echo -e "\t\tmegalinter_exec --input /megalinter --output /tmp/output.sarif --capture-std /tmp/out.log"
echo -e ""
}

INPUT=""
Expand All @@ -42,65 +41,65 @@ ML_ENV_FIX_COMMAND="set -a; . ${ML_ENV_VARS}; set +a"

# parse command line arguments
while :; do
case $1 in
-h|-\?|--help)
usage
exit
;;
# options
-v|--verbose)
VERBOSE=1
;;
# arguments
--input)
if [ -n "$2" ]; then
INPUT=$2
shift
else
printf 'ERROR: "--input" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--output)
if [ -n "$2" ]; then
OUTPUT=$2
shift
else
printf 'ERROR: "--output" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--capture-std)
if [ -n "$2" ]; then
CAPTURE_STD=$2
shift
else
printf 'ERROR: "--capture-std" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: If no more options then break out of the loop.
break
esac
shift
case $1 in
-h | -\? | --help)
usage
exit
;;
# options
-v | --verbose)
VERBOSE=1
;;
# arguments
--input)
if [ -n "$2" ]; then
INPUT=$2
shift
else
printf 'ERROR: "--input" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--output)
if [ -n "$2" ]; then
OUTPUT=$2
shift
else
printf 'ERROR: "--output" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--capture-std)
if [ -n "$2" ]; then
CAPTURE_STD=$2
shift
else
printf 'ERROR: "--capture-std" requires a non-empty option argument.\n' >&2
exit 1
fi
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: If no more options then break out of the loop.
break ;;
esac
shift
done

## prepare Megalinter scan command
if [ "${INPUT}" == "" ]; then
printf 'ERROR: No input given (--input)\n' >&2
exit 1
printf 'ERROR: No input given (--input)\n' >&2
exit 1
fi

if [ "${OUTPUT}" == "" ]; then
printf 'ERROR: No output given (--output)\n' >&2
exit 1
printf 'ERROR: No output given (--output)\n' >&2
exit 1
fi

echo "Setting git safe.directory to /tmp/lint and ${INPUT} ..."
Expand All @@ -109,16 +108,16 @@ git config --global --add safe.directory "${INPUT}"

MEGALINTER_SCAN_COMMAND="DEFAULT_WORKSPACE=${INPUT} python -m megalinter.run --output ${OUTPUT}"
if [ "${CAPTURE_STD}" != "" ]; then
MEGALINTER_SCAN_COMMAND="${MEGALINTER_SCAN_COMMAND} &> ${CAPTURE_STD}"
MEGALINTER_SCAN_COMMAND="${MEGALINTER_SCAN_COMMAND} &> ${CAPTURE_STD}"
fi
## prepare bash command
if [ "${VERBOSE}" == "1" ]; then
echo "The Megalinter Scan command is: ${MEGALINTER_SCAN_COMMAND}"
echo "The Megalinter Scan command is: ${MEGALINTER_SCAN_COMMAND}"
fi
BASH_COMMAND_TO_EXECUTE="${ML_ENV_FIX_COMMAND}; ${MEGALINTER_SCAN_COMMAND}"
if [ "${VERBOSE}" == "1" ]; then
echo "About to run the following scan command (also setting -x): ${BASH_COMMAND_TO_EXECUTE}"
set -x
echo "About to run the following scan command (also setting -x): ${BASH_COMMAND_TO_EXECUTE}"
set -x
fi
## run bash command
bash --login -c "${BASH_COMMAND_TO_EXECUTE}"
bash --login -c "${BASH_COMMAND_TO_EXECUTE}"

0 comments on commit 36f75b2

Please sign in to comment.