cmd/cue: rewrite `exp writefs` with internal/filetypes and internal/encoding
This means that we automatically support all output filetypes that
cmd/cue supports via e.g. `cue export --out`,
as well as all the filename extension detection.
No change in behavior to existing features, other than the "text" form
now adding a newline at the end of the contents,
again matching cmd/cue's behavior.
This makes sense to me too, as writing a text file without a trailing
newline is generally considered to be an anti-pattern.
The only other noteworthy change is that we used to always fall back
to "text" as the encoding when one could not be derived from a
filename extension. We keep that for cases where there is no extension,
but for any case where there is an unknown extension, we drop that
as we want the user to use the upcoming `encoding: "text"` field.
Otherwise, adding a new encoding like xml would silently break users,
as writing a file like
"foo.xml": contents: "some string"
would suddenly switch from writing the string as text
to writing the string as an XML value without a warning.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ia2880a36478b025f356d594f6106cb6a4a61125f
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1232053
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.io>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>