add --help option and usage string
This commit is contained in:
parent
d59e186ed9
commit
2278a4c16b
16
src/dfmt.d
16
src/dfmt.d
|
@ -34,13 +34,29 @@ import std.d.formatter;
|
||||||
import std.d.ast;
|
import std.d.ast;
|
||||||
import std.array;
|
import std.array;
|
||||||
|
|
||||||
|
immutable USAGE = "usage: %s [--inplace] [<path>...]
|
||||||
|
Formats D code.
|
||||||
|
|
||||||
|
--inplace change file in-place instead of outputing to stdout
|
||||||
|
(implicit in case of multiple files)
|
||||||
|
-h, --help display this help and exit
|
||||||
|
";
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
import std.getopt;
|
import std.getopt;
|
||||||
|
|
||||||
bool inplace = false;
|
bool inplace = false;
|
||||||
|
bool show_usage = false;
|
||||||
getopt(args,
|
getopt(args,
|
||||||
|
"help|h", &show_usage,
|
||||||
"inplace", &inplace);
|
"inplace", &inplace);
|
||||||
|
if (show_usage)
|
||||||
|
{
|
||||||
|
import std.path: baseName;
|
||||||
|
writef(USAGE, baseName(args[0]));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
File output = stdout;
|
File output = stdout;
|
||||||
ubyte[] buffer;
|
ubyte[] buffer;
|
||||||
args.popFront();
|
args.popFront();
|
||||||
|
|
Loading…
Reference in New Issue