We're trying to deprecate $wgCommandLineMode, as it is mostly redundant to constants defined in entry points, and its mutable nature complicates debugging. This is one of the repositories currently using it.
In most cases checks for $wgCommandLineMode can be replaced with MW_ENTRY_POINT === 'cli', but some cases are trickier, particularly if your code writes to the variable rather than only reads from it.