From 6e9448bdbb508fa5e98fd1e717f39a8091189814 Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Tue, 13 Jan 2015 22:15:32 +0100 Subject: [PATCH] add --inplace option --- src/dfmt.d | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dfmt.d b/src/dfmt.d index c1fb1fd..1f1132e 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -33,9 +33,14 @@ import std.d.parser; import std.d.formatter; import std.d.ast; import std.array; +import std.getopt; int main(string[] args) { + bool inplace = false; + getopt(args, + "inplace", &inplace); + File output = stdout; ubyte[] buffer; if (args.length == 1) { @@ -55,6 +60,8 @@ int main(string[] args) File f = File(args[1]); buffer = new ubyte[](f.size); f.rawRead(buffer); + if (inplace) + output = File(args[1], "w"); } LexerConfig config; config.stringBehavior = StringBehavior.source; @@ -71,7 +78,7 @@ int main(string[] args) visitor.visit(mod); astInformation.cleanup(); auto tokens = byToken(buffer, config, &cache).array(); - auto tokenFormatter = TokenFormatter(tokens, stdout, &astInformation, + auto tokenFormatter = TokenFormatter(tokens, output, &astInformation, &formatterConfig); tokenFormatter.format(); return 0;