(PUP-3511) refactor Application.run for reuse

Extract a small chunk of code from Puppet::Application.run into its own
method so that it can be reused.  This code is currently duplicated in
Puppet Server; the introduction of this new `reset_environment_context`
method enables the replacement of the duplicated code in Puppet Server
with a call to this new method.
This could also use documentation, but I don't really know what this is doing so I cannot explain it well :-) If you know more something that helps the next developer reading this would be awesome, if not, it is not worse than before...