Add option to look for sources in alternate root paths

Add a new optional flag "-r|--root ROOTPATHS", where ROOTPATHS is a
colon separated list of paths, that will look for external sources in
alternate roots.

This is particular useful when the run-time environment does not fully
match the development environment. The #shellcheck source=file directive
is useful, but has its limitations in certain scenarios. Also, in many
cases the directive could be removed from scripts when the root flag is
used.

Script example.bash:
  #!/bin/bash
  source /etc/foo/config

Example usage where etc/foo/config exists in skel/foo:
  # shellcheck -x -r skel/foo:skel/core example.bash
This commit is contained in:
Pontus Andersson 2019-04-22 14:34:38 +02:00
parent b824294961
commit af46758ff1
3 changed files with 37 additions and 1 deletions

View file

@ -2087,7 +2087,9 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d
input <-
if filename == "/dev/null" -- always allow /dev/null
then return (Right "")
else system $ siReadFile sys filename
else do
filename' <- system $ siFindSource sys filename
system $ siReadFile sys filename'
case input of
Left err -> do
parseNoteAtId (getId file) InfoC 1091 $