Refactor: Table driven compiler and variable logging. by trulede · Pull Request #2739 · go-task/task

For consideration.

A refactoring of the compiler to use a table driven approach, especially the getVariables() function and introduction of variable logging to assist in Taskfile debug. No functional change.

Additional?

Operation

Currently the logging is enabled by a "secret" environment variable and the -v flag. The intention is to integrate the debug into a more capable logging framework where a log category can be assigned (see PR #2617).

This logging is disabled by default because the output impacts some test fixtures ... and there is a lot of it!

Unchanged (by Task) environment variables are not printed by the logging, which reduces the volume of logs significantly, and avoids, but does not prevent, printing of sensitive data.

TASK_DEBUG_COMPILER=1 task -v -t testdata/compiler/debug_compiler/Taskfile.yml 2>&1 | less -R

Output ... there is a lot of it

FastGetVariables: task=default, call=default
  compiler: variable merge: OS.Env
  compiler: variable merge: SpecialVars
    TASK_EXE <-- task
    ROOT_DIR <-- /home/trule/git/task/testdata/compiler/debug_compiler
    USER_WORKING_DIR <-- /home/trule/git/task
    TASK_VERSION <-- 3.49.1
    TASK <-- default
    TASK_DIR <-- /home/trule/git/task/testdata/compiler/debug_compiler
    TASKFILE <-- /home/trule/git/task/testdata/compiler/debug_compiler/Taskfile.yml
    TASKFILE_DIR <-- /home/trule/git/task/testdata/compiler/debug_compiler
    ROOT_TASKFILE <-- /home/trule/git/task/testdata/compiler/debug_compiler/Taskfile.yml
    ALIAS <-- default
  compiler: variable merge: Taskfile.Env
    TASKFILE_ENV <-- taskfile_env
  compiler: variable merge: Taskfile.Vars
    CLI_ARGS <-- 
    CLI_ARGS_LIST <-- []
    CLI_FORCE <-- false
    CLI_SILENT <-- false
    CLI_VERBOSE <-- true
    CLI_OFFLINE <-- false
    CLI_ASSUME_YES <-- false
    TASKFILE_VAR <-- taskfile_var
  compiler: variable merge: Inc.Vars
  compiler: variable merge: IncTaskfile.Vars
  compiler: variable merge: Call.Vars
    MATCH <-- []
  compiler: variable merge: Task.Vars
    TASK_VAR <-- task_var
GetVariables: task=default, call=default
  compiler: variable merge: OS.Env
  compiler: variable merge: SpecialVars
    TASK_EXE <-- task