Extra context: API + CLI

Fixes #12
Synthesizes parts of: #75, #100, #116, #161 and #199.
Thanks @fcurella, @aventurella, @emonty, @schacki, @ryanolson!
I would have preferred to leave the encoding explicit in this call, as it makes it easier to spot where explicit encodings are needed as & when we add project-defined encodings. But the write_file function does have an encoding argument, so it can be added later, I guess.