mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-22 08:41:02 -05:00
Better pswh module validation
This commit is contained in:
parent
da41dfe6fb
commit
87036c3987
1 changed files with 6 additions and 26 deletions
|
@ -210,36 +210,16 @@ function GetValidationInfo() {
|
|||
#### Function ValidatePowershellModules ########################################
|
||||
function ValidatePowershellModules() {
|
||||
VALIDATE_PSSA_MODULE=$(pwsh -c "(Get-Module -Name PSScriptAnalyzer -ListAvailable | Select-Object -First 1).Name" 2>&1)
|
||||
VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1)
|
||||
# If module found, ensure Invoke-ScriptAnalyzer command is available
|
||||
if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]]; then
|
||||
VALIDATE_PSSA_CMD=$(pwsh -c "(Get-Command Invoke-ScriptAnalyzer | Select-Object -First 1).Name" 2>&1)
|
||||
else
|
||||
fatal "Failed to find module."
|
||||
fi
|
||||
|
||||
#########################################
|
||||
# validate we found the script analyzer #
|
||||
#########################################
|
||||
if [[ ${VALIDATE_PSSA_CMD} != "Invoke-ScriptAnalyzer" ]]; then
|
||||
fatal "Failed to find module."
|
||||
fi
|
||||
|
||||
#######################
|
||||
# Load the error code #
|
||||
#######################
|
||||
ERROR_CODE=$?
|
||||
|
||||
##############################
|
||||
# Check the shell for errors #
|
||||
##############################
|
||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||
# Failed
|
||||
error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!"
|
||||
fatal "[PSSA_MODULE ${VALIDATE_PSSA_MODULE}] [PSSA_CMD ${VALIDATE_PSSA_CMD}]"
|
||||
else
|
||||
if [[ ${VALIDATE_PSSA_MODULE} == "PSScriptAnalyzer" ]] && [[ ${VALIDATE_PSSA_CMD} == "Invoke-ScriptAnalyzer" ]]; then
|
||||
# Success
|
||||
debug "Successfully found module ${F[W]}[${VALIDATE_PSSA_MODULE}]${F[B]} in system"
|
||||
debug "Successfully found command ${F[W]}[${VALIDATE_PSSA_CMD}]${F[B]} in system"
|
||||
else
|
||||
# Failed
|
||||
error "Failed find module [PSScriptAnalyzer] for [${LINTER_NAME}] in system!"
|
||||
fatal "[PSSA_MODULE: ${VALIDATE_PSSA_MODULE}] [PSSA_CMD: ${VALIDATE_PSSA_CMD}]"
|
||||
fi
|
||||
}
|
||||
################################################################################
|
||||
|
|
Loading…
Reference in a new issue