Added command-line help
This commit is contained in:
parent
851df54c09
commit
ce3ce23099
71
main.d
71
main.d
|
@ -128,7 +128,7 @@ string[] loadConfig()
|
||||||
return dirs;
|
return dirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
string[] importDirs;
|
string[] importDirs;
|
||||||
bool sloc;
|
bool sloc;
|
||||||
|
@ -139,18 +139,25 @@ void main(string[] args)
|
||||||
bool ctags;
|
bool ctags;
|
||||||
bool recursiveCtags;
|
bool recursiveCtags;
|
||||||
bool format;
|
bool format;
|
||||||
|
bool help;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
getopt(args, "I", &importDirs, "dotComplete", &dotComplete, "sloc", &sloc,
|
getopt(args, "I", &importDirs, "dotComplete", &dotComplete, "sloc", &sloc,
|
||||||
"json", &json, "parenComplete", &parenComplete, "highlight", &highlight,
|
"json", &json, "parenComplete", &parenComplete, "highlight", &highlight,
|
||||||
"ctags", &ctags, "recursive|r|R", &recursiveCtags);
|
"ctags", &ctags, "recursive|r|R", &recursiveCtags, "help|h", &help);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
stderr.writeln(e.msg);
|
stderr.writeln(e.msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (help)
|
||||||
|
{
|
||||||
|
printHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
importDirs ~= loadConfig();
|
importDirs ~= loadConfig();
|
||||||
|
|
||||||
if (sloc)
|
if (sloc)
|
||||||
|
@ -168,8 +175,7 @@ void main(string[] args)
|
||||||
writeln(args[1..$].map!(a => a.readText().tokenize())().joiner()
|
writeln(args[1..$].map!(a => a.readText().tokenize())().joiner()
|
||||||
.count!(a => isLineOfCode(a.type))());
|
.count!(a => isLineOfCode(a.type))());
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highlight)
|
if (highlight)
|
||||||
|
@ -186,7 +192,7 @@ void main(string[] args)
|
||||||
{
|
{
|
||||||
highlighter.highlight(args[1].readText().tokenize(IterationStyle.EVERYTHING));
|
highlighter.highlight(args[1].readText().tokenize(IterationStyle.EVERYTHING));
|
||||||
}
|
}
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dotComplete || parenComplete)
|
if (dotComplete || parenComplete)
|
||||||
|
@ -225,7 +231,7 @@ void main(string[] args)
|
||||||
writeln(complete.parenComplete(to!size_t(args[1])));
|
writeln(complete.parenComplete(to!size_t(args[1])));
|
||||||
else if (dotComplete)
|
else if (dotComplete)
|
||||||
writeln(complete.dotComplete(to!size_t(args[1])));
|
writeln(complete.dotComplete(to!size_t(args[1])));
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json)
|
if (json)
|
||||||
|
@ -233,6 +239,7 @@ void main(string[] args)
|
||||||
Token[] tokens;
|
Token[] tokens;
|
||||||
if (args.length == 1)
|
if (args.length == 1)
|
||||||
{
|
{
|
||||||
|
// Read from stdin
|
||||||
auto f = appender!string();
|
auto f = appender!string();
|
||||||
char[] buf;
|
char[] buf;
|
||||||
while (stdin.readln(buf))
|
while (stdin.readln(buf))
|
||||||
|
@ -241,11 +248,12 @@ void main(string[] args)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// read given file
|
||||||
tokens = tokenize(readText(args[1]));
|
tokens = tokenize(readText(args[1]));
|
||||||
}
|
}
|
||||||
auto mod = parseModule(tokens);
|
auto mod = parseModule(tokens);
|
||||||
mod.writeJSONTo(stdout);
|
mod.writeJSONTo(stdout);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctags)
|
if (ctags)
|
||||||
|
@ -276,4 +284,53 @@ void main(string[] args)
|
||||||
m.writeCtagsTo(stdout, "");
|
m.writeCtagsTo(stdout, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printHelp()
|
||||||
|
{
|
||||||
|
writeln(
|
||||||
|
q{
|
||||||
|
Usage: dscanner options
|
||||||
|
|
||||||
|
options:
|
||||||
|
--help | -h
|
||||||
|
Prints this help message
|
||||||
|
|
||||||
|
--sloc [sourceFiles]
|
||||||
|
count the number of logical lines of code in the given
|
||||||
|
source files. If no files are specified, a file is read from stdin.
|
||||||
|
|
||||||
|
--json [sourceFile]
|
||||||
|
Generate a JSON summary of the given source file. If no file is
|
||||||
|
specifed, the file is read from stdin.
|
||||||
|
|
||||||
|
--dotComplete [sourceFile] cursorPosition
|
||||||
|
Provide autocompletion for the insertion of the dot operator. The cursor
|
||||||
|
position is the character position in the *file*, not the position in
|
||||||
|
the line. If no file is specified, the file is read from stdin.
|
||||||
|
|
||||||
|
--parenComplete [sourceFile] cursorPosition
|
||||||
|
Provides a listing of function parameters or pre-defined version
|
||||||
|
identifiers at the cursor position. The cursor position is the character
|
||||||
|
position in the *file*, not the line. If no file is specified, the
|
||||||
|
contents are read from stdin.
|
||||||
|
|
||||||
|
--highlight [sourceFile] - Syntax-highlight the given source file. The
|
||||||
|
resulting HTML will be written to standard output.
|
||||||
|
|
||||||
|
-I includePath
|
||||||
|
Include _includePath_ in the list of paths used to search for imports.
|
||||||
|
By default dscanner will search in the current working directory as
|
||||||
|
well as any paths specified in /etc/dmd.conf. This is only used for the
|
||||||
|
--parenComplete and --dotComplete options.
|
||||||
|
|
||||||
|
--ctags sourceFile
|
||||||
|
Generates ctags information from the given source code file. Note that
|
||||||
|
ctags information requires a filename, so stdin cannot be used in place
|
||||||
|
of a filename.
|
||||||
|
|
||||||
|
--recursive | -R | -r directory
|
||||||
|
When used with --ctags, dscanner will produce ctags output for all .d
|
||||||
|
and .di files contained within directory and its sub-directories.});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue