Fix commands with iterative values
i.e., gh pr --open --number 21 --number 1
Number is an interative value of the gh pull-request command.
The hook structure is broken and gh will crash because the afterHooksCallback callback is undefined on the second run.
The problem is being caused because of a race condition between the hook functionality and the iterative values functionality.
The hooks are designed to be used once in a time and rely on some global state, such as the NODEGH_HOOK_IS_LOCKED environmental variable.
However, when you trigger gh pull-request --open --number x --number y the pull-request open command is executed twice (in parallel).
Killing the hooks functionality is out of question.
If we kill the parallelism, operations will have lower performance and the hooks will work again. The impact is that it'd be slower, given that most gh operations requires remote calls.
The best option I see is that we stop abusing global variables right away.
Mostly, we can just pass the needed parameters to the new process invoked on the hook creation (in case it's gh).
The following are all instances of global / environmental variables we currently use on GH:
- GH_VERBOSE (safe)
- GH_PATH (safe)
- GH_GIT_COMMAND (safe)
- NODEGH_PLUGIN (maybe unsafe)
- NODEGH_HOOK_IS_LOCKED (unsafe)